some initial work on local only config
This commit is contained in:
parent
406df8c27a
commit
bac19670f7
2 changed files with 47 additions and 13 deletions
|
|
@ -47,6 +47,10 @@ export default {
|
|||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
local: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
parentPath: {
|
||||
type: [String, Array],
|
||||
},
|
||||
|
|
@ -259,11 +263,17 @@ export default {
|
|||
const writePath = `simple.${readPath}`
|
||||
|
||||
if (!this.timedApplyMode) {
|
||||
useSyncConfigStore().setSimplePrefAndSave({
|
||||
path: writePath,
|
||||
value,
|
||||
})
|
||||
useSyncConfigStore().pushSyncConfig()
|
||||
if (this.local) {
|
||||
useLocalConfigStore().set({
|
||||
path: writePath,
|
||||
value,
|
||||
})
|
||||
} else {
|
||||
useSyncConfigStore().setSimplePrefAndSave({
|
||||
path: writePath,
|
||||
value,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
|
||||
console.error("Can't track more than one temporary change")
|
||||
|
|
@ -272,18 +282,30 @@ export default {
|
|||
|
||||
const oldValue = get(this.configSource, readPath)
|
||||
|
||||
useSyncConfigStore().setPreference({ path: writePath, value })
|
||||
if (this.local) {
|
||||
useLocalConfigStore().setTemporarily({ path: writePath, value })
|
||||
} else {
|
||||
useSyncConfigStore().setPreference({ path: writePath, value })
|
||||
}
|
||||
|
||||
const confirm = () => {
|
||||
useSyncConfigStore().pushSyncConfig()
|
||||
if (this.local) {
|
||||
useLocalConfigStore().set({ path: writePath, value })
|
||||
} else {
|
||||
useSyncConfigStore().pushSyncConfig()
|
||||
}
|
||||
useInterfaceStore().clearTemporaryChanges()
|
||||
}
|
||||
|
||||
const revert = () => {
|
||||
useSyncConfigStore().setPreference({
|
||||
path: writePath,
|
||||
value: oldValue,
|
||||
})
|
||||
if (this.local) {
|
||||
useLocalConfigStore().unsetTemporarily({ path: writePath, value })
|
||||
} else {
|
||||
useSyncConfigStore().setPreference({
|
||||
path: writePath,
|
||||
value: oldValue,
|
||||
})
|
||||
}
|
||||
useInterfaceStore().clearTemporaryChanges()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ export const defaultState = {
|
|||
prefsStorage: {
|
||||
...configDefaultState,
|
||||
},
|
||||
tempStorage: {
|
||||
...configDefaultState
|
||||
}
|
||||
}
|
||||
|
||||
export const useLocalConfigStore = defineStore('local_config', {
|
||||
|
|
@ -20,6 +23,12 @@ export const useLocalConfigStore = defineStore('local_config', {
|
|||
set({ path, value }) {
|
||||
set(this.prefsStorage, path, value)
|
||||
},
|
||||
setTemporarily({ path, value }) {
|
||||
set(this.tempStorage, path, value)
|
||||
},
|
||||
unsetTemporarily({ path, value }) {
|
||||
set(this.tempStorage, path, undefined)
|
||||
},
|
||||
unset({ path, value }) {
|
||||
set(this.prefsStorage, path, undefined)
|
||||
},
|
||||
|
|
@ -36,7 +45,7 @@ export const useLocalConfigStore = defineStore('local_config', {
|
|||
const result = Object.fromEntries(
|
||||
Object.entries(state.prefsStorage).map(([k, v]) => [
|
||||
k,
|
||||
v ?? instancePrefs[k],
|
||||
state.tempStorage[k] ?? v ?? instancePrefs[k],
|
||||
]),
|
||||
)
|
||||
return result
|
||||
|
|
@ -44,7 +53,10 @@ export const useLocalConfigStore = defineStore('local_config', {
|
|||
},
|
||||
persist: {
|
||||
afterLoad(state) {
|
||||
return state
|
||||
return {
|
||||
prefStorage: state.prefsStorage,
|
||||
tempStorage: { ...configDefaultState },
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue