page + upload queue + folders
This commit is contained in:
@@ -39,15 +39,15 @@ function recordsToUnifiedItems(records: ReturnType<typeof fileStore.getRootFiles
|
||||
|
||||
export function useFiles(parentId?: string | null, page: number = 1, limit: number = 100) {
|
||||
const queryKey = parentId
|
||||
? ['resources', parentId]
|
||||
? ['resources', parentId, page, limit]
|
||||
: ['resources', 'root', page, limit];
|
||||
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: async () => {
|
||||
if (parentId) {
|
||||
const backendRes = await apiClient.get<{ data: FileItem[] }>(
|
||||
`${ENDPOINTS.RESOURCES}/folders/${parentId}/resources?thumbnail=thumbnail_small`,
|
||||
const backendRes = await apiClient.get<PaginatedResponse<FileItem>>(
|
||||
`${ENDPOINTS.RESOURCES}/folders/${parentId}/resources?page=${page}&limit=${limit}&thumbnail=thumbnail_small`,
|
||||
);
|
||||
fileStore.mergeFromBackend(
|
||||
backendRes.data.map((f) => ({
|
||||
@@ -69,7 +69,7 @@ export function useFiles(parentId?: string | null, page: number = 1, limit: numb
|
||||
const children = fileStore.getChildrenByParent(parentId);
|
||||
return {
|
||||
data: children.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
||||
meta: { page: 0, total: children.length },
|
||||
meta: { page, total: backendRes.meta?.total ?? children.length },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ export function usePullSync() {
|
||||
try {
|
||||
setIsSyncing(true);
|
||||
|
||||
const res = await apiClient.get<{ data: Array<{
|
||||
let page = 1;
|
||||
const limit = 100;
|
||||
let total = 0;
|
||||
const backendResources: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
mimeType: string;
|
||||
@@ -28,9 +31,17 @@ export function usePullSync() {
|
||||
url?: string;
|
||||
thumbnailUrl?: string;
|
||||
ownerId?: string;
|
||||
}> }>(`${ENDPOINTS.RESOURCES}?page=1&limit=100&thumbnail=thumbnail_small`);
|
||||
}> = [];
|
||||
|
||||
do {
|
||||
const res = await apiClient.get<{ data: Array<typeof backendResources[number]>; meta?: { total: number } }>(
|
||||
`${ENDPOINTS.RESOURCES}?page=${page}&limit=${limit}&thumbnail=thumbnail_small`,
|
||||
);
|
||||
backendResources.push(...(res.data ?? []));
|
||||
total = res.meta?.total ?? res.data.length;
|
||||
page++;
|
||||
} while (backendResources.length < total);
|
||||
|
||||
const backendResources = res.data ?? [];
|
||||
const registry = fileStore.getAllSynced();
|
||||
const existingBackendIds = new Set(
|
||||
registry.filter((e) => e.backendId).map((e) => e.backendId)
|
||||
|
||||
Reference in New Issue
Block a user