Save collapsed sections to localStorage

This commit is contained in:
James Lyne 2021-05-27 01:42:53 +01:00
parent 034a7a2fdb
commit 62ab0cf26e
3 changed files with 18 additions and 0 deletions

View File

@ -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) {

View File

@ -15,6 +15,8 @@
*/
export enum MutationTypes {
INIT ='init',
SET_SERVERS ='setServers',
SET_CONFIGURATION = 'setConfiguration',
SET_CONFIGURATION_HASH = 'setConfigurationHash',

View File

@ -39,6 +39,7 @@ export type CurrentMapPayload = {
}
export type Mutations<S = State> = {
[MutationTypes.INIT](state: S): void
[MutationTypes.SET_SERVERS](state: S, servers: Map<string, LiveAtlasServerDefinition>): 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<S = State> = {
}
export const mutations: MutationTree<State> & 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<string, LiveAtlasServerDefinition>) {
state.servers = config;