📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Fix preferences page (v-model not save) and remove double state "value" and "reactive", keep only reactive
Smaug67392e268c077d6d
diff --git a/frontend/app/composables/Preferences.ts b/frontend/app/composables/Preferences.tsindex 25daef54..b4f3f4fe 100644--- a/frontend/app/composables/Preferences.ts+++ b/frontend/app/composables/Preferences.ts@@ -74,7 +74,7 @@ function savePreferences() {export function usePreferences() {function get<K extends PreferenceKey>(key: K) {return computed<Preferences[K]>({- get: () => preferences[key],+ get: () => preferences[key] as Preferences[K],set: val => {preferences[key] = val;savePreferences();@@ -103,48 +103,42 @@ export function usePreferences() {}type OptionType = 'toggle' | 'select' | 'color' | 'radio' | 'groupCheckbox' | 'anode';-interface BaseOption<T = unknown> {+interface BaseOption<K extends PreferenceKey = PreferenceKey> {label: string;description?: string;type: OptionType;- key: PreferenceKey;- onChange?: (value: T) => void;+ key: K;+ onChange?: (value: Preferences[K]) => void;}-interface ToggleOption extends BaseOption<boolean> {+interface ToggleOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'toggle';- value: boolean;- onChange?: (value: boolean) => void;}-interface ColorOption extends BaseOption<number> {++interface ColorOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'color';- value: number;- onChange?: (value: number) => void;+ items: Array<{ label: string; id: string | number }>;+ onChange?: (value: Preferences[K]) => void;}-interface SelectOption extends BaseOption<number | string> {+interface SelectOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'select';- value: number | string;choices: ANode[];- onChange?: (value: number | string) => void;+ onChange?: (value: Preferences[K]) => void;}-interface RadioOption extends BaseOption<number | string> {+interface RadioOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'radio';- value: number | string;choices: Array<{ id: number | string; label: string }>;- onChange?: (value: number | string) => void;+ onChange?: (value: Preferences[K]) => void;}-interface GroupCheckboxOption extends BaseOption<Record<string, boolean>> {+interface GroupCheckboxOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'groupCheckbox';- // Les sous-options sont un objet clé => labelitems: Record<string, string>;- value: Record<string, boolean>;- onChange?: (value: Record<string, boolean>) => void;+ onChange?: (value: Preferences[K]) => void;}-interface AnodeOption extends BaseOption<ANode[]> {+interface AnodeOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {type: 'anode';- value: ANode[];- onChange?: (value: ANode[]) => void;+ onChange?: (value: Preferences[K]) => void;}export type Option = ToggleOption | ColorOption | SelectOption | RadioOption | GroupCheckboxOption | AnodeOption;diff --git a/frontend/app/pages/dashboard/settings/_views/preferences.vue b/frontend/app/pages/dashboard/settings/_views/preferences.vueindex fe026f9e..6436054f 100644--- a/frontend/app/pages/dashboard/settings/_views/preferences.vue+++ b/frontend/app/pages/dashboard/settings/_views/preferences.vue@@ -12,34 +12,35 @@<p class="description">{{ opt.description }}</p></div><!-- Toggle -->- <AppToggle v-if="opt.type === 'toggle'" v-model="prefs[opt.key]" class="entry" @update:model-value="opt.onChange?.(prefs[opt.key])" />+ <AppToggle v-if="opt.type === 'toggle'" v-model="p(opt.key).value" class="entry" @update:model-value="opt.onChange?.(p(opt.key).value)" /><!-- Select --><AppSelectv-else-if="opt.type === 'select'"- v-model="prefs[opt.key]"+ v-model="p(opt.key).value":items="opt.choices!"size="40%"class="entry"- @update:model-value="opt.onChange?.(prefs[opt.key])"+ @update:model-value="opt.onChange?.(p(opt.key).value)"/><!-- Radio --><AppRadiov-else-if="opt.type === 'radio'"- v-model="prefs[opt.key]"+ v-model="p(opt.key).value":items="opt.choices!"class="entry"- @update:model-value="opt.onChange?.(prefs[opt.key])"+ @update:model-value="opt.onChange?.(p(opt.key).value)"/><!-- Color -->- <AppColorPicker v-else-if="opt.type === 'color'" v-model="prefs[opt.key]" class="entry" @update:model-value="opt.onChange?.(prefs[opt.key])" />+ <AppColorPicker v-else-if="opt.type === 'color'" v-model="p(opt.key).value" class="entry" @update:model-value="opt.onChange?.(p(opt.key).value)" />+ <!-- Group Checkbox --><div v-else-if="opt.type === 'groupCheckbox'" class="group-checkbox"><div class="checkbox-grid">- <label v-for="(label, key) in opt.items" :key="key">- <AppCheck v-model="prefs[opt.key][key]" @change="opt.onChange?.(prefs[opt.key])">{{ label }}</AppCheck>+ <label v-for="[key, label] of Object.entries(opt.items)" :key="key">+ <AppCheck v-model="p(opt.key).value[key]" @change="opt.onChange?.(p(opt.key).value)">{{ label }}</AppCheck></label></div></div>@@ -59,17 +60,17 @@<script setup lang="ts">const preferencesStore = usePreferences();-// eslint-disable-next-line @typescript-eslint/no-explicit-any-const prefs: Record<string, any> = preferencesStore.all;+// @ts-expect-error unknown type+const p = preferencesStore.get as <K extends PreferenceKey>(key: K) => ReturnType<unknown>;+const colorMode = useColorMode();-const options = ref<{ label: string; options: Option[] }[]>([+const options: Array<{ label: string; options: Option[] }> = [{label: 'General',options: [{label: 'Enable Dark Mode',type: 'toggle',- value: Boolean(preferencesStore.get('darkMode')),key: 'darkMode',onChange: (option: boolean) => {colorMode.preference = option ? 'dark' : 'light';@@ -80,7 +81,6 @@ const options = ref<{ label: string; options: Option[] }[]>([label: 'Choose primary color',type: 'color',key: 'primaryColor',- value: Number(preferencesStore.get('primaryColor')),onChange: (option: number) => {setAppColor(option);},@@ -95,15 +95,13 @@ const options = ref<{ label: string; options: Option[] }[]>([description: 'Simplify the header of printed documents (remove the thumbnail, tags, description and keep only the title)',type: 'toggle',key: 'printMode',- value: Boolean(preferencesStore.get('printMode')),},- { label: 'Hide Table of Content', type: 'toggle', key: 'hideTOC', value: Boolean(preferencesStore.get('hideTOC')) },- { label: 'Enable Document auto-save', type: 'toggle', key: 'documentAutoSave', value: Boolean(preferencesStore.get('documentAutoSave')) },+ { label: 'Hide Table of Content', type: 'toggle', key: 'hideTOC' },+ { label: 'Enable Document auto-save', type: 'toggle', key: 'documentAutoSave' },{label: 'Document size',type: 'radio',key: 'docSize',- value: Number(preferencesStore.get('docSize')),choices: DOCUMENT_SIZES,},{@@ -111,7 +109,6 @@ const options = ref<{ label: string; options: Option[] }[]>([description: 'Default theme used for documents. You can override it for each document individually.',type: 'select',key: 'theme',- value: String(preferencesStore.get('theme')),choices: DOCUMENT_THEMES,},],@@ -124,43 +121,30 @@ const options = ref<{ label: string; options: Option[] }[]>([description: 'Reduce the size of the sidebar items to show more content on the screen.',type: 'toggle',key: 'compactMode',- value: Boolean(preferencesStore.get('compactMode')),},{label: 'View dock',description: 'Show the dock on the right side of the sidebar to access to the different apps quickly.',type: 'toggle',key: 'view_dock',- value: Boolean(preferencesStore.get('view_dock')),},{label: 'Normalize file icons',description: 'Display file parents with the same icon as classic files (not in green)',type: 'toggle',key: 'normalizeFileIcons',- value: Boolean(preferencesStore.get('normalizeFileIcons')),},{label: 'Display uncategorized ressources',description: 'Show resources (uploads from CDN) that are not categorized at the top of the sidebar.',type: 'toggle',key: 'displayUncategorizedRessources',- value: Boolean(preferencesStore.get('displayUncategorizedRessources')),},- { label: 'Hide ressources', type: 'toggle', key: 'hideSidebarRessources', value: Boolean(preferencesStore.get('hideSidebarRessources')) },+ { label: 'Hide ressources', type: 'toggle', key: 'hideSidebarRessources' },{label: 'Show items in Sidebar',type: 'groupCheckbox',key: 'sidebarItems',- value: {- manageCategories: true,- cdn: true,- settings: true,- home: true,- importation: false,- documents: true,- newPage: false,- },items: {manageCategories: 'Manage Categories',importation: 'Importation',@@ -180,12 +164,6 @@ const options = ref<{ label: string; options: Option[] }[]>([label: 'Show items in navbar',type: 'groupCheckbox',key: 'navbarItems',- value: {- breadcrumb: true,- search: true,- theme: true,- navigation: true,- },items: {breadcrumb: 'Breadcrumb',search: 'Search',@@ -202,14 +180,12 @@ const options = ref<{ label: string; options: Option[] }[]>([label: 'Editor font family',type: 'select',key: 'editorFontFamily',- value: String(preferencesStore.get('editorFontFamily')),choices: EDITOR_FONTS,},{label: 'Editor font size',type: 'select',key: 'editorFontSize',- value: Number(preferencesStore.get('editorFontSize')),choices: [{ label: '12', id: 12 },{ label: '14', id: 14 },@@ -225,14 +201,12 @@ const options = ref<{ label: string; options: Option[] }[]>([description: 'Enable spell check of browser in the editor. Changes may require a page reload to take effect.',type: 'toggle',key: 'editorSpellCheck',- value: Boolean(preferencesStore.get('editorSpellCheck')),},{label: 'Display statistics bar',description: 'Show a small statistics bar at the top of the editor with word count, characters, and lines.',type: 'toggle',key: 'editorDisplayStats',- value: Boolean(preferencesStore.get('editorDisplayStats')),},],},@@ -243,7 +217,6 @@ const options = ref<{ label: string; options: Option[] }[]>([label: 'Default datatable items count',type: 'select',key: 'datatableItemsCount',- value: Number(preferencesStore.get('datatableItemsCount')),choices: [{ label: '10', id: 10 },{ label: '30', id: 30 },@@ -262,11 +235,10 @@ const options = ref<{ label: string; options: Option[] }[]>([description: 'Enable additional debugging features and options like "Copy ID" in context menus.',type: 'toggle',key: 'developerMode',- value: Boolean(preferencesStore.get('developerMode')),},],},-]);+];</script><style scoped lang="scss">