it works more or less well now
This commit is contained in:
parent
6df9913354
commit
04f8c2d29d
@ -103,7 +103,6 @@ const NavPanel = {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
collapsed: false,
|
|
||||||
showTimelines: false,
|
showTimelines: false,
|
||||||
showLists: false,
|
showLists: false,
|
||||||
timelinesList: Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
|
timelinesList: Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
|
||||||
@ -118,7 +117,8 @@ const NavPanel = {
|
|||||||
this.showLists = !this.showLists
|
this.showLists = !this.showLists
|
||||||
},
|
},
|
||||||
toggleCollapse () {
|
toggleCollapse () {
|
||||||
this.collapsed = !this.collapsed
|
this.$store.commit('setPreference', { path: 'simple.collapseNav', value: !this.collapsed })
|
||||||
|
this.$store.dispatch('pushServerSideStorage')
|
||||||
},
|
},
|
||||||
isPinned (item) {
|
isPinned (item) {
|
||||||
return this.pinnedItems.has(item)
|
return this.pinnedItems.has(item)
|
||||||
@ -129,6 +129,7 @@ const NavPanel = {
|
|||||||
} else {
|
} else {
|
||||||
this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value: item })
|
this.$store.commit('addCollectionPreference', { path: 'collections.pinnedNavItems', value: item })
|
||||||
}
|
}
|
||||||
|
this.$store.dispatch('pushServerSideStorage')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -138,7 +139,8 @@ const NavPanel = {
|
|||||||
privateMode: state => state.instance.private,
|
privateMode: state => state.instance.private,
|
||||||
federating: state => state.instance.federating,
|
federating: state => state.instance.federating,
|
||||||
pleromaChatMessagesAvailable: state => state.instance.pleromaChatMessagesAvailable,
|
pleromaChatMessagesAvailable: state => state.instance.pleromaChatMessagesAvailable,
|
||||||
pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedNavItems)
|
pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedNavItems),
|
||||||
|
collapsed: state => state.serverSideStorage.prefsStorage.simple.collapseNav
|
||||||
}),
|
}),
|
||||||
rootItems () {
|
rootItems () {
|
||||||
return Object
|
return Object
|
||||||
|
@ -22,7 +22,8 @@ export const defaultState = {
|
|||||||
prefsStorage: {
|
prefsStorage: {
|
||||||
_journal: [],
|
_journal: [],
|
||||||
simple: {
|
simple: {
|
||||||
dontShowUpdateNotifs: false
|
dontShowUpdateNotifs: false,
|
||||||
|
collapseNav: false
|
||||||
},
|
},
|
||||||
collections: {
|
collections: {
|
||||||
pinnedNavItems: ['home', 'dms', 'chats', 'about']
|
pinnedNavItems: ['home', 'dms', 'chats', 'about']
|
||||||
@ -58,6 +59,23 @@ const _wrapData = (data) => ({
|
|||||||
|
|
||||||
const _checkValidity = (data) => data._timestamp > 0 && data._version > 0
|
const _checkValidity = (data) => data._timestamp > 0 && data._version > 0
|
||||||
|
|
||||||
|
const _verifyPrefs = (state) => {
|
||||||
|
state.prefsStorage = state.prefsStorage || {
|
||||||
|
simple: {},
|
||||||
|
collections: {}
|
||||||
|
}
|
||||||
|
Object.entries(defaultState.prefsStorage.simple).forEach(([k, v]) => {
|
||||||
|
if (typeof v === 'number' || typeof v === 'boolean') return
|
||||||
|
console.warn(`Preference simple.${k} as invalid type, reinitializing`)
|
||||||
|
set(state.prefsStorage.simple, k, defaultState.prefsStorage.simple[k])
|
||||||
|
})
|
||||||
|
Object.entries(defaultState.prefsStorage.collections).forEach(([k, v]) => {
|
||||||
|
if (Array.isArray(v)) return
|
||||||
|
console.warn(`Preference collections.${k} as invalid type, reinitializing`)
|
||||||
|
set(state.prefsStorage.collections, k, defaultState.prefsStorage.collections[k])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const _getRecentData = (cache, live) => {
|
export const _getRecentData = (cache, live) => {
|
||||||
const result = { recent: null, stale: null, needUpload: false }
|
const result = { recent: null, stale: null, needUpload: false }
|
||||||
const cacheValid = _checkValidity(cache || {})
|
const cacheValid = _checkValidity(cache || {})
|
||||||
@ -149,7 +167,8 @@ export const _mergePrefs = (recent, stale, allFlagKeys) => {
|
|||||||
*/
|
*/
|
||||||
const resultOutput = { ...recentData }
|
const resultOutput = { ...recentData }
|
||||||
const totalJournal = _mergeJournal(staleJournal, recentJournal)
|
const totalJournal = _mergeJournal(staleJournal, recentJournal)
|
||||||
totalJournal.forEach(({ path, timestamp, operation, args }) => {
|
totalJournal.forEach(({ path, timestamp, operation, command, args }) => {
|
||||||
|
operation = operation || command
|
||||||
if (path.startsWith('_')) {
|
if (path.startsWith('_')) {
|
||||||
console.error(`journal contains entry to edit internal (starts with _) field '${path}', something is incorrect here, ignoring.`)
|
console.error(`journal contains entry to edit internal (starts with _) field '${path}', something is incorrect here, ignoring.`)
|
||||||
return
|
return
|
||||||
@ -161,9 +180,12 @@ export const _mergePrefs = (recent, stale, allFlagKeys) => {
|
|||||||
case 'addToCollection':
|
case 'addToCollection':
|
||||||
set(resultOutput, path, Array.from(new Set(get(resultOutput, path)).add(args[0])))
|
set(resultOutput, path, Array.from(new Set(get(resultOutput, path)).add(args[0])))
|
||||||
break
|
break
|
||||||
case 'removeFromCollection':
|
case 'removeFromCollection': {
|
||||||
set(resultOutput, path, Array.from(new Set(get(resultOutput, path)).remove(args[0])))
|
const newSet = new Set(get(resultOutput, path))
|
||||||
|
newSet.delete(args[0])
|
||||||
|
set(resultOutput, path, Array.from(newSet))
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case 'reorderCollection': {
|
case 'reorderCollection': {
|
||||||
const [value, movement] = args
|
const [value, movement] = args
|
||||||
set(resultOutput, path, _moveItemInArray(get(resultOutput, path), value, movement))
|
set(resultOutput, path, _moveItemInArray(get(resultOutput, path), value, movement))
|
||||||
@ -269,6 +291,8 @@ export const mutations = {
|
|||||||
// Merge the flags
|
// Merge the flags
|
||||||
console.debug('Merging the data...')
|
console.debug('Merging the data...')
|
||||||
totalFlags = _mergeFlags(recent, stale, allFlagKeys)
|
totalFlags = _mergeFlags(recent, stale, allFlagKeys)
|
||||||
|
_verifyPrefs(recent)
|
||||||
|
_verifyPrefs(stale)
|
||||||
totalPrefs = _mergePrefs(recent.prefsStorage, stale.prefsStorage)
|
totalPrefs = _mergePrefs(recent.prefsStorage, stale.prefsStorage)
|
||||||
} else {
|
} else {
|
||||||
totalFlags = recent.flagStorage
|
totalFlags = recent.flagStorage
|
||||||
@ -301,8 +325,9 @@ export const mutations = {
|
|||||||
set(state.prefsStorage, path, value)
|
set(state.prefsStorage, path, value)
|
||||||
state.prefsStorage._journal = [
|
state.prefsStorage._journal = [
|
||||||
...state.prefsStorage._journal,
|
...state.prefsStorage._journal,
|
||||||
{ command: 'set', path, args: [value], timestamp: Date.now() }
|
{ operation: 'set', path, args: [value], timestamp: Date.now() }
|
||||||
]
|
]
|
||||||
|
state.dirty = true
|
||||||
},
|
},
|
||||||
addCollectionPreference (state, { path, value }) {
|
addCollectionPreference (state, { path, value }) {
|
||||||
if (path.startsWith('_')) {
|
if (path.startsWith('_')) {
|
||||||
@ -311,11 +336,12 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
const collection = new Set(get(state.prefsStorage, path))
|
const collection = new Set(get(state.prefsStorage, path))
|
||||||
collection.add(value)
|
collection.add(value)
|
||||||
set(state.prefsStorage, path, collection)
|
set(state.prefsStorage, path, [...collection])
|
||||||
state.prefsStorage._journal = [
|
state.prefsStorage._journal = [
|
||||||
...state.prefsStorage._journal,
|
...state.prefsStorage._journal,
|
||||||
{ command: 'addToCollection', path, args: [value], timestamp: Date.now() }
|
{ operation: 'addToCollection', path, args: [value], timestamp: Date.now() }
|
||||||
]
|
]
|
||||||
|
state.dirty = true
|
||||||
},
|
},
|
||||||
removeCollectionPreference (state, { path, value }) {
|
removeCollectionPreference (state, { path, value }) {
|
||||||
if (path.startsWith('_')) {
|
if (path.startsWith('_')) {
|
||||||
@ -324,11 +350,12 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
const collection = new Set(get(state.prefsStorage, path))
|
const collection = new Set(get(state.prefsStorage, path))
|
||||||
collection.delete(value)
|
collection.delete(value)
|
||||||
set(state.prefsStorage, path, collection)
|
set(state.prefsStorage, path, [...collection])
|
||||||
state.prefsStorage._journal = [
|
state.prefsStorage._journal = [
|
||||||
...state.prefsStorage._journal,
|
...state.prefsStorage._journal,
|
||||||
{ command: 'removeFromCollection', path, args: [value], timestamp: Date.now() }
|
{ operation: 'removeFromCollection', path, args: [value], timestamp: Date.now() }
|
||||||
]
|
]
|
||||||
|
state.dirty = true
|
||||||
},
|
},
|
||||||
reorderCollectionPreference (state, { path, value, movement }) {
|
reorderCollectionPreference (state, { path, value, movement }) {
|
||||||
if (path.startsWith('_')) {
|
if (path.startsWith('_')) {
|
||||||
@ -340,8 +367,9 @@ export const mutations = {
|
|||||||
set(state.prefsStorage, path, newCollection)
|
set(state.prefsStorage, path, newCollection)
|
||||||
state.prefsStorage._journal = [
|
state.prefsStorage._journal = [
|
||||||
...state.prefsStorage._journal,
|
...state.prefsStorage._journal,
|
||||||
{ command: 'arrangeCollection', path, args: [value], timestamp: Date.now() }
|
{ operation: 'arrangeCollection', path, args: [value], timestamp: Date.now() }
|
||||||
]
|
]
|
||||||
|
state.dirty = true
|
||||||
},
|
},
|
||||||
updateCache (state) {
|
updateCache (state) {
|
||||||
state.prefsStorage._journal = _mergeJournal(state.prefsStorage._journal)
|
state.prefsStorage._journal = _mergeJournal(state.prefsStorage._journal)
|
||||||
@ -365,8 +393,10 @@ const serverSideStorage = {
|
|||||||
const params = { pleroma_settings_store: { 'pleroma-fe': state.cache } }
|
const params = { pleroma_settings_store: { 'pleroma-fe': state.cache } }
|
||||||
rootState.api.backendInteractor
|
rootState.api.backendInteractor
|
||||||
.updateProfile({ params })
|
.updateProfile({ params })
|
||||||
.then((user) => commit('setServerSideStorage', user))
|
.then((user) => {
|
||||||
state.dirty = false
|
commit('setServerSideStorage', user)
|
||||||
|
state.dirty = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user