pleroma-fe/src/stores/local_config.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2026-02-23 20:14:39 +02:00
import { cloneDeep, set } from 'lodash'
import { defineStore } from 'pinia'
import { toRaw } from 'vue'
import { useInstanceStore } from 'src/stores/instance'
2026-03-24 20:04:46 +02:00
import {
LOCAL_DEFAULT_CONFIG,
LOCAL_DEFAULT_CONFIG_DEFINITIONS
} from 'src/modules/default_config_state'
export const defaultState = {
prefsStorage: {
2026-03-24 20:04:46 +02:00
...LOCAL_DEFAULT_CONFIG,
2026-02-23 20:14:39 +02:00
},
2026-02-24 21:16:38 +02:00
tempStorage: {
2026-03-24 20:04:46 +02:00
...LOCAL_DEFAULT_CONFIG,
2026-03-06 15:25:30 +02:00
},
}
export const useLocalConfigStore = defineStore('local_config', {
state() {
return cloneDeep(defaultState)
},
actions: {
set({ path, value }) {
2026-03-24 20:04:46 +02:00
const definition = LOCAL_DEFAULT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path,
value,
definition,
throwError: false,
defaultState: LOCAL_DEFAULT_CONFIG,
})
set(this.prefsStorage, path, finalValue)
},
2026-02-24 21:16:38 +02:00
setTemporarily({ path, value }) {
set(this.tempStorage, path, value)
},
unsetTemporarily({ path, value }) {
set(this.tempStorage, path, undefined)
},
unset({ path, value }) {
set(this.prefsStorage, path, undefined)
},
clearLocalConfig() {
Object.keys(this).forEach((k) => {
2026-03-18 15:08:52 +02:00
this.prefsStorage[k] = undefined
this.tempStorage[k] = undefined
})
},
},
persist: {
afterLoad(state) {
2026-02-24 21:16:38 +02:00
return {
prefsStorage: state.prefsStorage ?? { ...configDefaultState },
2026-02-24 21:16:38 +02:00
tempStorage: { ...configDefaultState },
}
},
},
})