minimal working
This commit is contained in:
1 parent
2093433b96
commit
13ea8c80da
11 files changed
+727
-337
No files matched your search
+45
-32
@@ -1,4 +1,5 @@
|
||||
import { actionTree, getAccessorType, mutationTree } from 'typed-vuex'
|
||||
|
||||
import { api } from '~/assets/api'
|
||||
import { jsonClone } from '~/assets/util'
|
||||
|
||||
@@ -29,6 +30,24 @@ export const state = () => ({
|
||||
identifier: '',
|
||||
})
|
||||
|
||||
const SET_ALL_TABS = (
|
||||
s: ReturnType<typeof state>,
|
||||
o: {
|
||||
tabs: ITab[]
|
||||
activeTab: number
|
||||
} = s
|
||||
) => {
|
||||
localStorage.setItem(
|
||||
TAB_SETTINGS,
|
||||
JSON.stringify({
|
||||
tabs: o.tabs,
|
||||
activeTabs: o.activeTab,
|
||||
})
|
||||
)
|
||||
s.tabs = jsonClone(o.tabs)
|
||||
s.activeTab = jsonClone(o.activeTab)
|
||||
}
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
SET_SETTINGS(state, settings: ISettings) {
|
||||
state.settings = settings
|
||||
@@ -36,26 +55,17 @@ export const mutations = mutationTree(state, {
|
||||
SET_IS_APP(state, isApp: boolean) {
|
||||
state.isApp = isApp
|
||||
},
|
||||
SET_ALL_TABS(
|
||||
state,
|
||||
o: {
|
||||
tabs: ITab[]
|
||||
activeTab: number
|
||||
} = state
|
||||
) {
|
||||
localStorage.setItem(
|
||||
TAB_SETTINGS,
|
||||
JSON.stringify({
|
||||
tabs: o.tabs,
|
||||
activeTabs: o.activeTab,
|
||||
})
|
||||
)
|
||||
state.tabs = jsonClone(o.tabs)
|
||||
state.activeTab = jsonClone(o.activeTab)
|
||||
},
|
||||
SET_TAB_TITLE(state, { i, title }: { i: number; title: string }) {
|
||||
state.tabs[i].title = title
|
||||
this.SET_ALL_TABS(state)
|
||||
if (state.tabs[i]) {
|
||||
state.tabs[i]!.title = title
|
||||
SET_ALL_TABS(state)
|
||||
}
|
||||
},
|
||||
SET_ALL_TABS(state) {
|
||||
const settings = localStorage.getItem(TAB_SETTINGS)
|
||||
if (settings) {
|
||||
Object.assign(state, JSON.parse(settings))
|
||||
}
|
||||
},
|
||||
ADD_TAB(
|
||||
state,
|
||||
@@ -90,7 +100,7 @@ export const mutations = mutationTree(state, {
|
||||
}
|
||||
|
||||
state.activeTab = state.tabs.length - 1
|
||||
this.SET_ALL_TABS(state)
|
||||
SET_ALL_TABS(state)
|
||||
},
|
||||
DELETE_TAB(state, { i }: { i: number }) {
|
||||
state.tabs.splice(i, 1)
|
||||
@@ -99,15 +109,17 @@ export const mutations = mutationTree(state, {
|
||||
state.activeTab = state.tabs.length - 1
|
||||
}
|
||||
|
||||
this.SET_ALL_TABS(state)
|
||||
SET_ALL_TABS(state)
|
||||
},
|
||||
SET_TAB_COMPONENT(state, { i, component }: { i: number; component: string }) {
|
||||
state.tabs[i].component = component
|
||||
this.SET_ALL_TABS(state)
|
||||
if (state.tabs[i]) {
|
||||
state.tabs[i]!.component = component
|
||||
SET_ALL_TABS(state)
|
||||
}
|
||||
},
|
||||
SET_TAB_CURRENT(state, { i }: { i: number }) {
|
||||
state.activeTab = i
|
||||
this.SET_ALL_TABS(state)
|
||||
SET_ALL_TABS(state)
|
||||
},
|
||||
SET_IDENTIFIER(state, name: string) {
|
||||
state.identifier = name
|
||||
@@ -117,16 +129,15 @@ export const mutations = mutationTree(state, {
|
||||
export const actions = actionTree(
|
||||
{ state, mutations },
|
||||
{
|
||||
async nuxtServerInit({ dispatch, commit }) {
|
||||
await dispatch('updateSetings')
|
||||
|
||||
const settings = localStorage.getItem(TAB_SETTINGS)
|
||||
if (settings) commit('SET_ALL_TABS', JSON.parse(settings))
|
||||
async nuxtServerInit({ commit }) {
|
||||
commit('SET_ALL_TABS')
|
||||
},
|
||||
async updateSettings({ commit }) {
|
||||
const r = await api.user_getSettings({
|
||||
select: ['identifier', 'levelMin', 'level'],
|
||||
})
|
||||
const r = await api
|
||||
.user_getSettings({
|
||||
select: ['identifier', 'levelMin', 'level'],
|
||||
})
|
||||
.catch(() => null)
|
||||
commit('SET_IS_APP', !!r)
|
||||
commit('SET_IDENTIFIER', r?.identifier || '')
|
||||
|
||||
@@ -144,6 +155,8 @@ export const actions = actionTree(
|
||||
level: r?.level || null,
|
||||
levelMin: r?.levelMin || null,
|
||||
})
|
||||
|
||||
return !!r
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user