Files
colanode/apps/desktop/src/renderer/components/files/file-container.tsx

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-25 00:37:50 +01:00
import { extractEntryRole } from '@colanode/core';
2024-12-02 00:44:02 +01:00
2024-11-12 11:12:26 +01:00
import { FileBody } from '@/renderer/components/files/file-body';
2024-12-02 00:44:02 +01:00
import { FileHeader } from '@/renderer/components/files/file-header';
import { useWorkspace } from '@/renderer/contexts/workspace';
import { useQuery } from '@/renderer/hooks/use-query';
interface FileContainerProps {
2024-12-25 00:37:50 +01:00
fileId: string;
}
2024-12-25 00:37:50 +01:00
export const FileContainer = ({ fileId }: FileContainerProps) => {
const workspace = useWorkspace();
const { data: file, isPending: isFilePending } = useQuery({
type: 'file_get',
2024-12-25 00:37:50 +01:00
id: fileId,
userId: workspace.userId,
});
2024-12-25 00:37:50 +01:00
const { data: entries, isPending: isEntriesPending } = useQuery(
{
2024-12-25 00:37:50 +01:00
type: 'entry_tree_get',
entryId: file?.parentId ?? '',
userId: workspace.userId,
},
{
enabled: !!file,
}
);
2024-12-25 00:37:50 +01:00
if (isFilePending || isEntriesPending) {
return null;
}
2024-12-25 00:37:50 +01:00
const role = extractEntryRole(entries ?? [], workspace.userId);
if (!file || !role) {
2024-11-11 21:33:55 +01:00
return null;
}
return (
2024-11-11 21:33:55 +01:00
<div className="flex h-full w-full flex-col">
2024-12-25 00:37:50 +01:00
<FileHeader entries={entries ?? []} file={file} role={role} />
2024-11-12 11:12:26 +01:00
<FileBody file={file} />
</div>
);
};