d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import type { QueryClient } from '@tanstack/react-query'
|
|
import type { WorkspaceFileFolderApi } from '@/lib/api/contracts/workspace-file-folders'
|
|
import type { ListWorkspaceFilesResponse } from '@/lib/api/contracts/workspace-files'
|
|
import { prefetchInternalJson } from '@/app/workspace/[workspaceId]/lib/prefetch-internal-fetch'
|
|
import {
|
|
WORKSPACE_FILE_FOLDERS_STALE_TIME,
|
|
workspaceFileFolderKeys,
|
|
} from '@/hooks/queries/workspace-file-folders'
|
|
import {
|
|
WORKSPACE_FILES_LIST_STALE_TIME,
|
|
workspaceFilesKeys,
|
|
} from '@/hooks/queries/workspace-files'
|
|
|
|
/**
|
|
* Prefetches the Files browser's two lists — workspace files and file folders —
|
|
* under the same query keys their client hooks (`useWorkspaceFiles`,
|
|
* `useWorkspaceFileFolders`) use (scope `active`), so the browser paints
|
|
* populated on first render.
|
|
*
|
|
* Both payloads carry `Date` fields, so they go through their routes and cache
|
|
* the serialized wire shape — see {@link prefetchInternalJson}.
|
|
*/
|
|
export async function prefetchFilesBrowser(
|
|
queryClient: QueryClient,
|
|
workspaceId: string
|
|
): Promise<void> {
|
|
await Promise.all([
|
|
queryClient.prefetchQuery({
|
|
queryKey: workspaceFilesKeys.list(workspaceId, 'active'),
|
|
queryFn: async () => {
|
|
const data = await prefetchInternalJson<ListWorkspaceFilesResponse>(
|
|
`/api/workspaces/${workspaceId}/files?scope=active`
|
|
)
|
|
return data.success ? data.files : []
|
|
},
|
|
staleTime: WORKSPACE_FILES_LIST_STALE_TIME,
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: workspaceFileFolderKeys.list(workspaceId, 'active'),
|
|
queryFn: async () => {
|
|
const data = await prefetchInternalJson<{ folders?: WorkspaceFileFolderApi[] }>(
|
|
`/api/workspaces/${workspaceId}/files/folders?scope=active`
|
|
)
|
|
return data.folders ?? []
|
|
},
|
|
staleTime: WORKSPACE_FILE_FOLDERS_STALE_TIME,
|
|
}),
|
|
])
|
|
}
|