diff --git a/src/main.ts b/src/main.ts index 6d0e488..2f88fef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,9 +42,16 @@ if(splash) { console.info(`LiveAtlas version ${store.state.version} - https://github.com/JLyne/LiveAtlas`); +store.subscribe((mutation, state) => { + if(mutation.type === 'toggleSidebarSectionCollapsedState' || mutation.type === 'setSidebarSectionCollapsedState') { + localStorage.setItem('collapsedSections', JSON.stringify(Array.from(state.ui.sidebar.collapsedSections))); + } +}); + try { const config = validateConfiguration(); + store.commit(MutationTypes.INIT, undefined); store.commit(MutationTypes.SET_SERVERS, config); if(config.size > 1) { diff --git a/src/store/mutation-types.ts b/src/store/mutation-types.ts index 0842125..bf26145 100644 --- a/src/store/mutation-types.ts +++ b/src/store/mutation-types.ts @@ -15,6 +15,8 @@ */ export enum MutationTypes { + INIT ='init', + SET_SERVERS ='setServers', SET_CONFIGURATION = 'setConfiguration', SET_CONFIGURATION_HASH = 'setConfigurationHash', diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 89f0be2..bd0932e 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -39,6 +39,7 @@ export type CurrentMapPayload = { } export type Mutations = { + [MutationTypes.INIT](state: S): void [MutationTypes.SET_SERVERS](state: S, servers: Map): void [MutationTypes.SET_CONFIGURATION](state: S, config: DynmapServerConfig): void [MutationTypes.SET_CONFIGURATION_HASH](state: S, hash: number): void @@ -90,6 +91,14 @@ export type Mutations = { } export const mutations: MutationTree & Mutations = { + [MutationTypes.INIT](state: State) { + const collapsedSections = localStorage.getItem('collapsedSections'); + + if(collapsedSections) { + state.ui.sidebar.collapsedSections = new Set(JSON.parse(collapsedSections)); + } + }, + // Sets configuration options from the initial config fetch [MutationTypes.SET_SERVERS](state: State, config: Map) { state.servers = config;