Save collapsed sections to localStorage
This commit is contained in:
parent
034a7a2fdb
commit
62ab0cf26e
@ -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) {
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
|
||||
export enum MutationTypes {
|
||||
INIT ='init',
|
||||
|
||||
SET_SERVERS ='setServers',
|
||||
SET_CONFIGURATION = 'setConfiguration',
|
||||
SET_CONFIGURATION_HASH = 'setConfigurationHash',
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user