diff --git a/packages/client/src/handlers/queries/files/local-file-get.ts b/packages/client/src/handlers/queries/files/local-file-get.ts index dd1f69e0..f386f0b8 100644 --- a/packages/client/src/handlers/queries/files/local-file-get.ts +++ b/packages/client/src/handlers/queries/files/local-file-get.ts @@ -1,12 +1,18 @@ import { WorkspaceQueryHandlerBase } from '@colanode/client/handlers/queries/workspace-query-handler-base'; -import { mapDownload, mapLocalFile } from '@colanode/client/lib/mappers'; +import { + mapDownload, + mapLocalFile, + mapNode, +} from '@colanode/client/lib/mappers'; import { ChangeCheckResult, QueryHandler } from '@colanode/client/lib/types'; import { LocalFileGetQueryInput, LocalFileGetQueryOutput, } from '@colanode/client/queries'; +import { LocalFileNode } from '@colanode/client/types'; import { Event } from '@colanode/client/types/events'; import { DownloadType } from '@colanode/client/types/files'; +import { FileStatus } from '@colanode/core'; export class LocalFileGetQueryHandler extends WorkspaceQueryHandlerBase @@ -136,6 +142,27 @@ export class LocalFileGetQueryHandler } if (input.autoDownload) { + const fileNode = await workspace.database + .selectFrom('nodes') + .selectAll() + .where('id', '=', input.fileId) + .executeTakeFirst(); + + if (!fileNode) { + return { + localFile: null, + download: null, + }; + } + + const file = mapNode(fileNode) as LocalFileNode; + if (file.attributes.status !== FileStatus.Ready) { + return { + localFile: null, + download: null, + }; + } + const download = await workspace.files.initAutoDownload(input.fileId); return { diff --git a/packages/ui/src/components/files/file-block.tsx b/packages/ui/src/components/files/file-block.tsx index 2f6cfb52..7bebec9f 100644 --- a/packages/ui/src/components/files/file-block.tsx +++ b/packages/ui/src/components/files/file-block.tsx @@ -1,5 +1,7 @@ import { LocalFileNode } from '@colanode/client/types'; +import { FileStatus } from '@colanode/core'; import { FileIcon } from '@colanode/ui/components/files/file-icon'; +import { FileNotUploaded } from '@colanode/ui/components/files/file-not-uploaded'; import { FilePreview } from '@colanode/ui/components/files/file-preview'; import { useLayout } from '@colanode/ui/contexts/layout'; import { useWorkspace } from '@colanode/ui/contexts/workspace'; @@ -26,8 +28,22 @@ export const FileBlock = ({ id }: FileBlockProps) => { } const file = nodeGetQuery.data as LocalFileNode; + const isReady = file.attributes.status === FileStatus.Ready; const canPreview = canPreviewFile(file.attributes.subtype); + if (!isReady) { + return ( +
+ The file has not been fully uploaded by the author yet.
+
You will be able to preview or download it once it is fully
+ uploaded.
+