get local files
This commit is contained in:
@@ -85,22 +85,30 @@ export function useFiles(parentId?: string | null, page: number = 1, limit: numb
|
|||||||
);
|
);
|
||||||
|
|
||||||
const cached = fileStore.getRootFiles();
|
const cached = fileStore.getRootFiles();
|
||||||
|
const localDeviceFiles = fileStore.getLocalDeviceFiles();
|
||||||
const validFiles = cached.files.filter(
|
const validFiles = cached.files.filter(
|
||||||
(f) => !f.backendId || returnedIds.has(f.backendId) || f.source === 'local',
|
(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 {
|
return {
|
||||||
data: validFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
data: mergedFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
||||||
meta: { page, total: backendRes.meta?.total ?? cached.total },
|
meta: { page, total: (backendRes.meta?.total ?? cached.total) + extraLocal.length },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
placeholderData: keepPreviousData,
|
placeholderData: keepPreviousData,
|
||||||
initialData: () => {
|
initialData: () => {
|
||||||
if (!parentId) {
|
if (!parentId) {
|
||||||
const cached = fileStore.getRootFiles();
|
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 {
|
return {
|
||||||
data: cached.files.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
data: allFiles.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
||||||
meta: { page: 0, total: cached.total },
|
meta: { page: 0, total: cached.total + extraLocal.length },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const children = fileStore.getChildrenByParent(parentId);
|
const children = fileStore.getChildrenByParent(parentId);
|
||||||
|
|||||||
@@ -562,6 +562,15 @@ export const fileStore = {
|
|||||||
return rows.map((r) => rowToRecord(r, getTagsForFile(r.id)));
|
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[] {
|
getAllSynced(): FileRecord[] {
|
||||||
const d = getDb();
|
const d = getDb();
|
||||||
const rows = d.select().from(files)
|
const rows = d.select().from(files)
|
||||||
|
|||||||
Reference in New Issue
Block a user