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/components/SettingsModal.vue | 104 +++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 60 deletions(-) (limited to 'src/components/SettingsModal.vue') diff --git a/src/components/SettingsModal.vue b/src/components/SettingsModal.vue index c4f896d..b4fa251 100644 --- a/src/components/SettingsModal.vue +++ b/src/components/SettingsModal.vue @@ -12,61 +12,43 @@ export default defineComponent({ }, data(){ return { - optChgd: false, + changedLytOpts: new Set(), + changedUiOpts: new Set(), }; }, methods: { onCloseClick(evt: Event){ if (evt.target == this.$el || (this.$refs.closeIcon as typeof CloseIcon).$el.contains(evt.target)){ - if (this.optChgd){ - this.saveSettings(); - } - this.$emit('close'); + this.$emit('close', this.changedLytOpts, this.changedUiOpts); } }, - onOptChg(){ - this.optChgd = true; - }, - onLytOptChg(){ - this.$emit('layout-setting-chg'); - this.onOptChg(); - }, - onMinTileSzChg(){ - let minInput = this.$refs.minTileSzInput as HTMLInputElement; - let maxInput = this.$refs.maxTileSzInput as HTMLInputElement; - if (Number(minInput.value) > Number(maxInput.value)){ - this.lytOpts.maxTileSz = this.lytOpts.minTileSz; - } - this.onLytOptChg(); - }, - onMaxTileSzChg(){ - let minInput = this.$refs.minTileSzInput as HTMLInputElement; - let maxInput = this.$refs.maxTileSzInput as HTMLInputElement; - if (Number(maxInput.value) < Number(minInput.value)){ - this.lytOpts.minTileSz = this.lytOpts.maxTileSz; + onLytOptChg(opt: string){ + if (opt == 'minTileSz'){ + let minInput = this.$refs.minTileSzInput as HTMLInputElement; + let maxInput = this.$refs.maxTileSzInput as HTMLInputElement; + if (Number(minInput.value) > Number(maxInput.value)){ + this.lytOpts.maxTileSz = this.lytOpts.minTileSz; + this.changedLytOpts.add('maxTileSz'); + } + } else if (opt == 'maxTileSz'){ + let minInput = this.$refs.minTileSzInput as HTMLInputElement; + let maxInput = this.$refs.maxTileSzInput as HTMLInputElement; + if (Number(maxInput.value) < Number(minInput.value)){ + this.lytOpts.minTileSz = this.lytOpts.maxTileSz; + this.changedLytOpts.add('minTileSz'); + } } - this.onLytOptChg(); - }, - onTreeChg(){ - this.$emit('tree-chg'); - this.onOptChg(); + this.$emit('layout-setting-chg'); + this.changedLytOpts.add(opt); }, - saveSettings(){ - const savedLytOpts = ['tileSpacing', 'minTileSz', 'maxTileSz', 'layoutType', 'sweepMode', 'sweepToParent', ]; - for (let prop of savedLytOpts){ - localStorage.setItem('lyt ' + prop, String(this.lytOpts[prop as keyof LayoutOptions])); + onUiOptChg(opt: string){ + if (opt == 'useReducedTree'){ + this.$emit('tree-chg'); } - const savedUiOpts = ['tileChgDuration', 'jumpToSearchedNode', 'useReducedTree', ]; - for (let prop of savedUiOpts){ - localStorage.setItem('ui ' + prop, String(this.uiOpts[prop])); - } - console.log('Settings saved'); + this.changedUiOpts.add(opt); }, onReset(){ - localStorage.clear(); - this.optChgd = false; this.$emit('reset'); - console.log('Settings reset'); }, }, components: {CloseIcon, RButton, }, @@ -84,21 +66,21 @@ export default defineComponent({
+ v-model.number="lytOpts.tileSpacing" @input="onLytOptChg('tileSpacing')"/>


@@ -107,15 +89,15 @@ export default defineComponent({ @@ -125,15 +107,15 @@ export default defineComponent({ @@ -143,31 +125,33 @@ export default defineComponent({
+ v-model.number="uiOpts.tileChgDuration" @change="onUiOptChg('tileChgDuration')"/>

- +

@@ -175,11 +159,11 @@ export default defineComponent({
-- cgit v1.2.3