Compare commits
2 commits
8765491399
...
1f2c96a485
Author | SHA1 | Date | |
---|---|---|---|
1f2c96a485 | |||
e274adf47d |
1 changed files with 26 additions and 18 deletions
|
@ -22,7 +22,7 @@ export const multiChoiceProperties = [
|
||||||
|
|
||||||
export const defaultState = {
|
export const defaultState = {
|
||||||
profile: 'default',
|
profile: 'default',
|
||||||
profileVersion: 0,
|
profileVersion: 0, // internal fe copy of server-side version
|
||||||
expertLevel: 0, // used to track which settings to show and hide
|
expertLevel: 0, // used to track which settings to show and hide
|
||||||
colors: {},
|
colors: {},
|
||||||
theme: undefined,
|
theme: undefined,
|
||||||
|
@ -127,6 +127,21 @@ export const instanceDefaultProperties = Object.entries(defaultState)
|
||||||
.filter(([key, value]) => value === undefined)
|
.filter(([key, value]) => value === undefined)
|
||||||
.map(([key, value]) => key)
|
.map(([key, value]) => key)
|
||||||
|
|
||||||
|
function updateLocalSettings(store, settingEntries, version = null) {
|
||||||
|
if (version == null)
|
||||||
|
version = store.state.profileVersion
|
||||||
|
|
||||||
|
settingEntries.forEach(([name, value]) => {
|
||||||
|
if (store.state[name] !== value) {
|
||||||
|
store.dispatch('setOption', { name, value })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Set this at the end to override any potentially stored profileVersion
|
||||||
|
store.commit('setOption', { name: 'profileVersion', value: version })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
state: { ...defaultState },
|
state: { ...defaultState },
|
||||||
getters: {
|
getters: {
|
||||||
|
@ -198,19 +213,17 @@ const config = {
|
||||||
store.dispatch('listSettingsProfiles')
|
store.dispatch('listSettingsProfiles')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
loadSettings ({ dispatch }, data) {
|
loadSettings (store, data) {
|
||||||
const knownKeys = new Set(Object.keys(defaultState))
|
const knownKeys = new Set(Object.keys(defaultState))
|
||||||
const presentKeys = new Set(Object.keys(data))
|
|
||||||
const intersection = new Set()
|
|
||||||
for (let elem of presentKeys) {
|
|
||||||
if (knownKeys.has(elem)) {
|
|
||||||
intersection.add(elem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
intersection.forEach(
|
// Limit to supported properties
|
||||||
name => dispatch('setOption', { name, value: data[name] })
|
const newSettingEntries =
|
||||||
)
|
Object.entries(data)
|
||||||
|
.filter(([key, value]) => knownKeys.has(key))
|
||||||
|
|
||||||
|
// disregard stored profileVersion; sync afterwards increases previous version
|
||||||
|
updateLocalSettings(store, newSettingEntries, null)
|
||||||
|
store.dispatch('syncSettings')
|
||||||
},
|
},
|
||||||
setHighlight ({ commit, dispatch }, { user, color, type }) {
|
setHighlight ({ commit, dispatch }, { user, color, type }) {
|
||||||
commit('setHighlight', { user, color, type })
|
commit('setHighlight', { user, color, type })
|
||||||
|
@ -244,12 +257,7 @@ const config = {
|
||||||
.then(({ settings, version }) => {
|
.then(({ settings, version }) => {
|
||||||
console.log('found settings version', version)
|
console.log('found settings version', version)
|
||||||
if (forceUpdate || (version > store.state.profileVersion)) {
|
if (forceUpdate || (version > store.state.profileVersion)) {
|
||||||
store.commit('setOption', { name: 'profileVersion', value: version })
|
updateLocalSettings(store, Object.entries(settings), version)
|
||||||
Object.entries(settings).forEach(([name, value]) => {
|
|
||||||
if (store.state[name] !== value) {
|
|
||||||
store.dispatch('setOption', { name, value })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
console.log('settings are up to date')
|
console.log('settings are up to date')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue