2024-11-11 21:33:55 +01:00
|
|
|
import { extractNodeRole } 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 {
|
|
|
|
|
nodeId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileContainer = ({ nodeId }: FileContainerProps) => {
|
|
|
|
|
const workspace = useWorkspace();
|
2024-12-22 17:47:39 +01:00
|
|
|
|
|
|
|
|
const { data: file, isPending: isFilePending } = useQuery({
|
|
|
|
|
type: 'file_get',
|
|
|
|
|
id: nodeId,
|
2024-10-23 18:33:49 +02:00
|
|
|
userId: workspace.userId,
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-22 17:47:39 +01:00
|
|
|
const { data: nodes, isPending: isNodesPending } = useQuery(
|
|
|
|
|
{
|
|
|
|
|
type: 'node_tree_get',
|
|
|
|
|
nodeId: file?.parentId ?? '',
|
|
|
|
|
userId: workspace.userId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
enabled: !!file,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isFilePending || isNodesPending) {
|
2024-10-23 18:33:49 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-22 17:47:39 +01:00
|
|
|
const role = extractNodeRole(nodes ?? [], workspace.userId);
|
|
|
|
|
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-22 17:47:39 +01:00
|
|
|
<FileHeader nodes={nodes ?? []} file={file} role={role} />
|
2024-11-12 11:12:26 +01:00
|
|
|
<FileBody file={file} />
|
2024-10-23 18:33:49 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|