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';
|
2024-10-23 18:33:49 +02:00
|
|
|
|
|
|
|
|
interface FileContainerProps {
|
2024-12-25 00:37:50 +01:00
|
|
|
fileId: string;
|
2024-10-23 18:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-25 00:37:50 +01:00
|
|
|
export const FileContainer = ({ fileId }: FileContainerProps) => {
|
2024-10-23 18:33:49 +02:00
|
|
|
const workspace = useWorkspace();
|
2024-12-22 17:47:39 +01:00
|
|
|
|
|
|
|
|
const { data: file, isPending: isFilePending } = useQuery({
|
|
|
|
|
type: 'file_get',
|
2024-12-25 00:37:50 +01:00
|
|
|
id: fileId,
|
2024-10-23 18:33:49 +02:00
|
|
|
userId: workspace.userId,
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-25 00:37:50 +01:00
|
|
|
const { data: entries, isPending: isEntriesPending } = useQuery(
|
2024-12-22 17:47:39 +01:00
|
|
|
{
|
2024-12-25 00:37:50 +01:00
|
|
|
type: 'entry_tree_get',
|
|
|
|
|
entryId: file?.parentId ?? '',
|
2024-12-22 17:47:39 +01:00
|
|
|
userId: workspace.userId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
enabled: !!file,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2024-12-25 00:37:50 +01:00
|
|
|
if (isFilePending || isEntriesPending) {
|
2024-10-23 18:33:49 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-25 00:37:50 +01:00
|
|
|
const role = extractEntryRole(entries ?? [], workspace.userId);
|
2024-12-22 17:47:39 +01:00
|
|
|
if (!file || !role) {
|
2024-11-11 21:33:55 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 18:33:49 +02:00
|
|
|
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} />
|
2024-10-23 18:33:49 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|