Remember last chosen tab on the settings UI.

This commit adds a UI setting that was accidentally lost from an
earlier PR.

It introduces `$utils.setPref()|getPref()` to save arbitrary key/value
preferences in a JSON blob under the app's namespace in localStorage.
This commit is contained in:
Kailash Nadh 2022-02-06 16:12:08 +05:30
parent 0f6a0376da
commit 93366f4e9e
2 changed files with 30 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
const reEmail = /(.+?)@(.+?)/ig;
const prefKey = 'listmonk_pref';
const htmlEntities = {
'&': '&',
@ -188,4 +189,23 @@ export default class Utils {
return obj;
};
getPref = (key) => {
if (localStorage.getItem(prefKey) === null) {
return null;
}
const p = JSON.parse(localStorage.getItem(prefKey));
return key in p ? p[key] : null;
};
setPref = (key, val) => {
let p = {};
if (localStorage.getItem(prefKey) !== null) {
p = JSON.parse(localStorage.getItem(prefKey));
}
p[key] = val;
localStorage.setItem(prefKey, JSON.stringify(p));
}
}

View file

@ -21,7 +21,7 @@
<hr />
<section class="wrap">
<b-tabs type="is-boxed" :animated="false">
<b-tabs type="is-boxed" :animated="false" v-model="tab">
<b-tab-item :label="$t('settings.general.name')" label-position="on-border">
<general-settings :form="form" :key="key" />
</b-tab-item><!-- general -->
@ -98,6 +98,7 @@ export default Vue.extend({
// form is compared to detect changes.
formCopy: '',
form: {},
tab: 0,
};
},
@ -237,7 +238,15 @@ export default Vue.extend({
},
mounted() {
this.tab = this.$utils.getPref('settings.tab') || 0;
this.getSettings();
},
watch: {
// Capture contentType and body passed from the parent as props.
tab(t) {
this.$utils.setPref('settings.tab', t);
},
},
});
</script>