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