some initial work on moving instance settings to pinia
This commit is contained in:
parent
20071d5a11
commit
9452b3084a
10 changed files with 559 additions and 195 deletions
|
|
@ -20,8 +20,9 @@ import {
|
|||
defaultState as configDefaultState,
|
||||
instanceDefaultConfig,
|
||||
} from 'src/modules/default_config_state'
|
||||
import { useInstanceStore } from 'src/stores/instance'
|
||||
|
||||
export const VERSION = 1
|
||||
export const VERSION = 2
|
||||
export const NEW_USER_DATE = new Date('2022-08-04') // date of writing this, basically
|
||||
|
||||
export const COMMAND_TRIM_FLAGS = 1000
|
||||
|
|
@ -45,11 +46,7 @@ export const defaultState = {
|
|||
dontShowUpdateNotifs: false,
|
||||
collapseNav: false,
|
||||
muteFilters: {},
|
||||
...{
|
||||
// reverting all the undefined to their initial values
|
||||
...configDefaultState,
|
||||
...instanceDefaultConfig,
|
||||
},
|
||||
...configDefaultState,
|
||||
},
|
||||
collections: {
|
||||
pinnedStatusActions: ['reply', 'retweet', 'favorite', 'emoji'],
|
||||
|
|
@ -377,21 +374,21 @@ export const _resetFlags = (
|
|||
return result
|
||||
}
|
||||
|
||||
export const _doMigrations = (cache) => {
|
||||
if (!cache) return cache
|
||||
export const _doMigrations = (cache, live) => {
|
||||
const data = cache ?? live
|
||||
|
||||
if (cache._version < VERSION) {
|
||||
if (data._version < VERSION) {
|
||||
console.debug(
|
||||
'Local cached data has older version, seeing if there any migrations that can be applied',
|
||||
'Data has older version, seeing if there any migrations that can be applied',
|
||||
)
|
||||
|
||||
// no migrations right now since we only have one version
|
||||
console.debug('No migrations found')
|
||||
}
|
||||
|
||||
if (cache._version > VERSION) {
|
||||
if (data._version > VERSION) {
|
||||
console.debug(
|
||||
'Local cached data has newer version, seeing if there any reverse migrations that can be applied',
|
||||
'Data has newer version, seeing if there any reverse migrations that can be applied',
|
||||
)
|
||||
|
||||
// no reverse migrations right now but we leave a possibility of loading a hotpatch if need be
|
||||
|
|
@ -401,8 +398,8 @@ export const _doMigrations = (cache) => {
|
|||
return window._PLEROMA_HOTPATCH.reverseMigrations.call(
|
||||
{},
|
||||
'serverSideStorage',
|
||||
{ from: cache._version, to: VERSION },
|
||||
cache,
|
||||
{ from: data._version, to: VERSION },
|
||||
data,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -580,7 +577,7 @@ export const useServerSideStorageStore = defineStore('serverSideStorage', {
|
|||
cache = null
|
||||
}
|
||||
|
||||
cache = _doMigrations(cache)
|
||||
cache = _doMigrations(cache, live)
|
||||
|
||||
let { recent, stale, needUpload } = _getRecentData(cache, live)
|
||||
|
||||
|
|
@ -649,6 +646,12 @@ export const useServerSideStorageStore = defineStore('serverSideStorage', {
|
|||
})
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
mergedConfig: (state) => ({
|
||||
...useInstanceStore().prefsStorage,
|
||||
...state.prefsStorage.simple,
|
||||
}),
|
||||
},
|
||||
persist: {
|
||||
afterLoad(state) {
|
||||
return state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue