From 4602f1da79acec70401830634034b6fa8e5506af Mon Sep 17 00:00:00 2001 From: m Date: Tue, 25 Aug 2026 17:48:47 +0200 Subject: [PATCH] get local files --- mobile/hooks/useFiles.ts | 18 +++++++++++++----- mobile/services/fileStore/index.ts | 9 +++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mobile/hooks/useFiles.ts b/mobile/hooks/useFiles.ts index 675b61a..d69d1b3 100644 --- a/mobile/hooks/useFiles.ts +++ b/mobile/hooks/useFiles.ts @@ -85,22 +85,30 @@ export function useFiles(parentId?: string | null, page: number = 1, limit: numb ); const cached = fileStore.getRootFiles(); + const localDeviceFiles = fileStore.getLocalDeviceFiles(); const validFiles = cached.files.filter( (f) => !f.backendId || returnedIds.has(f.backendId) || f.source === 'local', ); + const validIds = new Set(validFiles.map((f) => f.id)); + const extraLocal = localDeviceFiles.filter((f) => !validIds.has(f.id)); + const mergedFiles = [...validFiles, ...extraLocal]; return { - data: validFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean), - meta: { page, total: backendRes.meta?.total ?? cached.total }, + data: mergedFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean), + meta: { page, total: (backendRes.meta?.total ?? cached.total) + extraLocal.length }, }; }, placeholderData: keepPreviousData, initialData: () => { if (!parentId) { const cached = fileStore.getRootFiles(); - if (cached.files.length === 0) return undefined; + const localDeviceFiles = fileStore.getLocalDeviceFiles(); + const validIds = new Set(cached.files.map((f) => f.id)); + const extraLocal = localDeviceFiles.filter((f) => !validIds.has(f.id)); + const allFiles = [...cached.files, ...extraLocal]; + if (allFiles.length === 0) return undefined; return { - data: cached.files.map((r) => recordToUnifiedItem(r)!).filter(Boolean), - meta: { page: 0, total: cached.total }, + data: allFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean), + meta: { page: 0, total: cached.total + extraLocal.length }, }; } const children = fileStore.getChildrenByParent(parentId); diff --git a/mobile/services/fileStore/index.ts b/mobile/services/fileStore/index.ts index 71d931e..f23e3b0 100644 --- a/mobile/services/fileStore/index.ts +++ b/mobile/services/fileStore/index.ts @@ -562,6 +562,15 @@ export const fileStore = { return rows.map((r) => rowToRecord(r, getTagsForFile(r.id))); }, + getLocalDeviceFiles(): FileRecord[] { + const d = getDb(); + const rows = d.select().from(files) + .where(and(eq(files.source, 'local'), isNull(files.backendId))) + .orderBy(desc(files.createdAt)) + .all() as FileRow[]; + return rows.map((r) => rowToRecord(r, getTagsForFile(r.id))); + }, + getAllSynced(): FileRecord[] { const d = getDb(); const rows = d.select().from(files)