From 3ebfcdaa7d2c582e105e799266abd552e0df1fa2 Mon Sep 17 00:00:00 2001 From: static Date: Sat, 12 Jul 2025 18:14:33 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=98=EC=9C=84=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=EC=9D=98=20=ED=8C=8C=EC=9D=BC=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C=20=EC=97=AC=EB=B6=80=EB=A5=BC=20=EA=B8=B0=EC=96=B5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/indexedDB/filesystem.ts | 25 ++++++++-- src/lib/modules/filesystem.ts | 47 +++++++++++++++---- .../(main)/category/[[id]]/+page.svelte | 19 ++++++-- 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/lib/indexedDB/filesystem.ts b/src/lib/indexedDB/filesystem.ts index 1c2c060..cf60b93 100644 --- a/src/lib/indexedDB/filesystem.ts +++ b/src/lib/indexedDB/filesystem.ts @@ -25,6 +25,7 @@ interface CategoryInfo { parentId: CategoryId; name: string; files: { id: number; isRecursive: boolean }[]; + isFileRecursive: boolean; } const filesystem = new Dexie("filesystem") as Dexie & { @@ -33,11 +34,21 @@ const filesystem = new Dexie("filesystem") as Dexie & { category: EntityTable; }; -filesystem.version(2).stores({ - directory: "id, parentId", - file: "id, parentId", - category: "id, parentId", -}); +filesystem + .version(3) + .stores({ + directory: "id, parentId", + file: "id, parentId", + category: "id, parentId", + }) + .upgrade(async (trx) => { + await trx + .table("category") + .toCollection() + .modify((category) => { + category.isFileRecursive = false; + }); + }); export const getDirectoryInfos = async (parentId: DirectoryId) => { return await filesystem.directory.where({ parentId }).toArray(); @@ -87,6 +98,10 @@ export const storeCategoryInfo = async (categoryInfo: CategoryInfo) => { await filesystem.category.put(categoryInfo); }; +export const updateCategoryInfo = async (id: number, changes: { isFileRecursive?: boolean }) => { + await filesystem.category.update(id, changes); +}; + export const deleteCategoryInfo = async (id: number) => { await filesystem.category.delete(id); }; diff --git a/src/lib/modules/filesystem.ts b/src/lib/modules/filesystem.ts index eaf1d1a..c160534 100644 --- a/src/lib/modules/filesystem.ts +++ b/src/lib/modules/filesystem.ts @@ -12,6 +12,7 @@ import { getCategoryInfos as getCategoryInfosFromIndexedDB, getCategoryInfo as getCategoryInfoFromIndexedDB, storeCategoryInfo, + updateCategoryInfo as updateCategoryInfoInIndexedDB, deleteCategoryInfo, type DirectoryId, type CategoryId, @@ -62,6 +63,7 @@ export type CategoryInfo = name?: undefined; subCategoryIds: number[]; files?: undefined; + isFileRecursive?: undefined; } | { id: number; @@ -70,6 +72,7 @@ export type CategoryInfo = name: string; subCategoryIds: number[]; files: { id: number; isRecursive: boolean }[]; + isFileRecursive: boolean; }; const directoryInfoStore = new Map>(); @@ -255,7 +258,13 @@ const fetchCategoryInfoFromIndexedDB = async ( info.set({ id, subCategoryIds }); } else { if (!category) return; - info.set({ id, name: category.name, subCategoryIds, files: category.files }); + info.set({ + id, + name: category.name, + subCategoryIds, + files: category.files, + isFileRecursive: category.isFileRecursive, + }); } }; @@ -288,20 +297,28 @@ const fetchCategoryInfoFromServer = async ( const { files }: CategoryFileListResponse = await res.json(); const filesMapped = files.map(({ file, isRecursive }) => ({ id: file, isRecursive })); + let isFileRecursive: boolean | undefined = undefined; - info.set({ - id, - dataKey, - dataKeyVersion: new Date(metadata!.dekVersion), - name, - subCategoryIds: subCategories, - files: filesMapped, + info.update((value) => { + const newValue = { + isFileRecursive: false, + ...value, + id, + dataKey, + dataKeyVersion: new Date(metadata!.dekVersion), + name, + subCategoryIds: subCategories, + files: filesMapped, + }; + isFileRecursive = newValue.isFileRecursive; + return newValue; }); await storeCategoryInfo({ id, parentId: metadata!.parent, name, files: filesMapped, + isFileRecursive: isFileRecursive!, }); } }; @@ -327,3 +344,17 @@ export const getCategoryInfo = (categoryId: CategoryId, masterKey: CryptoKey) => fetchCategoryInfo(categoryId, info, masterKey); // Intended return info; }; + +export const updateCategoryInfo = async ( + categoryId: number, + changes: { isFileRecursive?: boolean }, +) => { + await updateCategoryInfoInIndexedDB(categoryId, changes); + categoryInfoStore.get(categoryId)?.update((value) => { + if (!value) return value; + if (changes.isFileRecursive !== undefined) { + value.isFileRecursive = changes.isFileRecursive; + } + return value; + }); +}; diff --git a/src/routes/(main)/category/[[id]]/+page.svelte b/src/routes/(main)/category/[[id]]/+page.svelte index 9bfa2a4..9cbc41c 100644 --- a/src/routes/(main)/category/[[id]]/+page.svelte +++ b/src/routes/(main)/category/[[id]]/+page.svelte @@ -3,7 +3,7 @@ import { goto } from "$app/navigation"; import { TopBar } from "$lib/components/molecules"; import { Category, CategoryCreateModal } from "$lib/components/organisms"; - import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem"; + import { getCategoryInfo, updateCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem"; import { masterKeyStore } from "$lib/stores"; import CategoryDeleteModal from "./CategoryDeleteModal.svelte"; import CategoryMenuBottomSheet from "./CategoryMenuBottomSheet.svelte"; @@ -21,7 +21,7 @@ let info: Writable | undefined = $state(); - let isFileRecursive = $state(false); + let isFileRecursive: boolean | undefined = $state(); let isCategoryCreateModalOpen = $state(false); let isCategoryMenuBottomSheetOpen = $state(false); @@ -30,6 +30,19 @@ $effect(() => { info = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); + isFileRecursive = undefined; + }); + + $effect(() => { + if ($info && isFileRecursive === undefined) { + isFileRecursive = $info.isFileRecursive ?? false; + } + }); + + $effect(() => { + if (data.id !== "root" && $info?.isFileRecursive !== isFileRecursive) { + updateCategoryInfo(data.id as number, { isFileRecursive }); + } }); @@ -41,7 +54,7 @@ {/if}
- {#if $info} + {#if $info && isFileRecursive !== undefined}