From 85e01e3f389cd3f42de8a72a00b3a860e222c41c Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Thu, 23 Jun 2022 21:39:39 +1000 Subject: Only save user-changed settings, and re-apply other settings on resize --- src/App.vue | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'src/App.vue') diff --git a/src/App.vue b/src/App.vue index 66db8c0..a622caf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,7 +58,7 @@ function getDefaultLytOpts(): LayoutOptions { rectMode: 'auto first-row', //'horz' | 'vert' | 'linear' | 'auto' | 'auto first-row' sweepMode: 'left', //'left' | 'top' | 'shorter' | 'auto' sweptNodesPrio: 'sqrt', //'linear' | 'sqrt' | 'pow-2/3' - sweepToParent: 'fallback', //'none' | 'prefer' | 'fallback' + sweepToParent: 'prefer', //'none' | 'prefer' | 'fallback' }; } function getDefaultUiOpts(){ @@ -575,7 +575,19 @@ export default defineComponent({ // Re-initialise tree this.initTreeFromServer(); }, + onSettingsClose(changedLytOpts: Set, changedUiOpts: Set){ + this.settingsOpen = false; + // Save changed settings + for (let opt of changedLytOpts){ + localStorage.setItem('lyt ' + opt, String(this.lytOpts[opt as keyof LayoutOptions])); + } + for (let opt of changedUiOpts){ + localStorage.setItem('ui ' + opt, String(this.uiOpts[opt])); + } + console.log('Settings saved'); + }, onResetSettings(){ + localStorage.clear(); let defaultLytOpts = getDefaultLytOpts(); let defaultUiOpts = getDefaultUiOpts(); if (this.uiOpts.useReducedTree != defaultUiOpts.useReducedTree){ @@ -583,6 +595,7 @@ export default defineComponent({ } Object.assign(this.lytOpts, defaultLytOpts); Object.assign(this.uiOpts, defaultUiOpts); + console.log('Settings reset'); this.relayoutWithCollapse(); }, // For help events @@ -644,9 +657,32 @@ export default defineComponent({ if (this.pendingResizeHdlr == 0){ const resizeDelay = 100; let handleResize = () => { - this.uiOpts.scrollGap = getScrollBarWidth(); + // Update unmodified layout/ui options with defaults + let lytOpts = getDefaultLytOpts(); + let uiOpts = getDefaultUiOpts(); + let changedTree = false; + for (let prop of Object.getOwnPropertyNames(lytOpts)){ + let item = localStorage.getItem('lyt ' + prop); + if (item == null && this.lytOpts[prop] != lytOpts[prop as keyof LayoutOptions]){ + this.lytOpts[prop] = lytOpts[prop as keyof LayoutOptions]; + } + } + for (let prop of Object.getOwnPropertyNames(uiOpts)){ + let item = localStorage.getItem('lyt ' + prop); + if (item == null && this.uiOpts[prop] != uiOpts[prop as keyof typeof uiOpts]){ + this.uiOpts[prop] = uiOpts[prop as keyof typeof uiOpts]; + if (prop == 'useReducedTree'){ + changedTree = true; + } + } + } + // this.overflownRoot = false; - return this.updateAreaDims().then(() => this.relayoutWithCollapse()); + if (!changedTree){ + return this.updateAreaDims().then(() => this.relayoutWithCollapse()); + } else { + return Promise.resolve(this.onTreeChange()); + } }; let currentTime = new Date().getTime(); if (currentTime - this.lastResizeHdlrTime > resizeDelay){ @@ -853,7 +889,7 @@ export default defineComponent({ @close="helpOpen = false" @start-tutorial="onStartTutorial"/>