📚 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
Local storage access improvment
Smaug673977a362c0fff5
diff --git a/frontend/app/components/Sidebar/CollapseItem.vue b/frontend/app/components/Sidebar/CollapseItem.vueindex bd6ae006..669fd067 100644--- a/frontend/app/components/Sidebar/CollapseItem.vue+++ b/frontend/app/components/Sidebar/CollapseItem.vue@@ -23,7 +23,7 @@ const props = defineProps<{ item: Item; root?: boolean }>();const toggleShow = () => {props.item.show.value = !props.item.show.value;- localStorage.setItem(`collapse-${props.item.id}`, props.item.show.value.toString());+ setCollapseState(props.item.id, props.item.show.value);};</script>diff --git a/frontend/app/components/Sidebar/Sidebar.vue b/frontend/app/components/Sidebar/Sidebar.vueindex 4b042ce0..2cb4b515 100644--- a/frontend/app/components/Sidebar/Sidebar.vue+++ b/frontend/app/components/Sidebar/Sidebar.vue@@ -22,7 +22,7 @@<div class="icons"><NuxtLink @click="onClick" to="/dashboard/docs/new"><Icon name="add_file" :mid="true" fill="var(--font-color)" /></NuxtLink><NuxtLink @click="newCategory"><Icon name="add_folder" :mid="true" fill="var(--font-color)" /></NuxtLink>- <NuxtLink @click="sidebarTree.collapseAll"><Icon name="collapse" :mid="true" fill="var(--font-color)" /></NuxtLink>+ <NuxtLink @click="collapseAllStates"><Icon name="collapse" :mid="true" fill="var(--font-color)" /></NuxtLink><NuxtLink @click="toggleDock"><Icon name="dock" :mid="true" fill="var(--font-color)" /></NuxtLink></div></div>diff --git a/frontend/app/components/Sidebar/SidebarItem.vue b/frontend/app/components/Sidebar/SidebarItem.vueindex 433dbf8a..c5727aa9 100644--- a/frontend/app/components/Sidebar/SidebarItem.vue+++ b/frontend/app/components/Sidebar/SidebarItem.vue@@ -76,7 +76,7 @@ const drop = async (event: DragEvent) => {}if (draggedItem.type === 'document' && props.item.data.type === 'document') {// Move document to document- if (documentStore.getAllChildrensIds(draggedItem.id).includes(props.item.parent_id)) return; // Prevent moving parent to child+ if (documentStore.getAllChildrensIds(draggedItem.id).includes(props.item.parent_id ?? '')) return; // Prevent moving parent to childif (draggedItem.id === props.item.id) return; // Prevent moving to the same documentdocumentStore.update({ ...draggedItem, parent_id: props.item.id, category: props.item.data.category });}diff --git a/frontend/app/composables/TreeStructure.ts b/frontend/app/composables/TreeStructure.tsindex 88ffb2aa..7419543a 100644--- a/frontend/app/composables/TreeStructure.ts+++ b/frontend/app/composables/TreeStructure.ts@@ -24,10 +24,7 @@ export class TreeStructure {public readonly childrenMap: Map<string, Item[]>; // Map for quick access to children by parent ID- private rootTree: Item[];-constructor(items: Item[]) {- console.log('MAIN: TreeStructure initialized with items:', items.length);this.items = items;this.itemMap = new Map(items.map(item => [item.id, item]));this.childrenMap = new Map();@@ -36,8 +33,6 @@ export class TreeStructure {if (!this.childrenMap.has(item.parent_id || '')) this.childrenMap.set(item.parent_id || '', []);this.childrenMap.get(item.parent_id || '')!.push(item);}-- this.rootTree = this.buildRootTree(); // calculé une seule fois}// Get item by ID@@ -45,12 +40,6 @@ export class TreeStructure {return this.itemMap.get(id);}- // Generate the tree structure without indexing- private buildRootTree(): Item[] {- console.log('TreeStructure reconstructed');- return this.items.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id || '') || (item.data.type === 'category' && item.data.role === 2)).map(root => this.buildTree(root));- }-public generateTree(): Item[] {return this.items.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id || '') || (item.data.type === 'category' && item.data.role === 2)).map(root => this.buildTree(root));}diff --git a/frontend/app/composables/collapseStates.ts b/frontend/app/composables/collapseStates.tsnew file mode 100644index 00000000..6533ff15--- /dev/null+++ b/frontend/app/composables/collapseStates.ts@@ -0,0 +1,45 @@+const STORAGE_KEY = 'collapse-states';++let collapseStateCache: Record<string, boolean> | null = null;++// Chargement depuis localStorage (une seule fois)+function loadCollapseStates(): Record<string, boolean> {+ if (!collapseStateCache) {+ try {+ const raw = localStorage.getItem(STORAGE_KEY);+ collapseStateCache = raw ? JSON.parse(raw) : {};+ } catch {+ collapseStateCache = {};+ }+ }+ return collapseStateCache!;+}++// Sauvegarde dans localStorage (entière map en une fois)+function saveCollapseStates() {+ if (collapseStateCache) {+ localStorage.setItem(STORAGE_KEY, JSON.stringify(collapseStateCache));+ }+}++export function collapseAllStates() {+ const states = loadCollapseStates();+ for (const key in states) {+ states[key] = false;+ }+ saveCollapseStates();+}++// Getter réactif+export function getCollapseState(id: string): Ref<boolean> {+ const states = loadCollapseStates();+ if (!(id in states)) states[id] = true; // défaut : ouvert+ return ref(states[id] ?? true);+}++// Setter (lié à la ref)+export function setCollapseState(id: string, value: boolean) {+ const states = loadCollapseStates();+ states[id] = value;+ saveCollapseStates();+}diff --git a/frontend/app/composables/useSidebarTree.ts b/frontend/app/composables/useSidebarTree.tsindex db07b653..30efbfb9 100644--- a/frontend/app/composables/useSidebarTree.ts+++ b/frontend/app/composables/useSidebarTree.ts@@ -9,11 +9,6 @@ const allItems = shallowRef<Item[]>([]);const structure = shallowRef<TreeStructure>(new TreeStructure(allItems.value));const tree = shallowRef<Item[]>([]);-function getCollapseState(id: string): boolean {- const stored = localStorage.getItem(`collapse-${id}`);- return stored !== 'false';-}-export function useSidebarTree() {const categoriesStore = useCategoriesStore();const documentsStore = useDocumentsStore();@@ -95,14 +90,6 @@ export function useSidebarTree() {});});- const collapseAll = () => {- tree.value.forEach(item => {- if (item.show.value) {- localStorage.setItem(`collapse-${item.id}`, 'false');- item.show.value = false;- }- });- };const getSubTreeById = (id: string) => {return structure.value.treeToArray(structure.value.getSubTreeById(id)?.childrens || []);};@@ -113,6 +100,5 @@ export function useSidebarTree() {categories,tree,filtered,- collapseAll,};}