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

63 lines
1.4 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();
2024-12-30 21:50:08 +01:00
const { data: file, isPending: isPendingFile } = useQuery({
type: 'file_get',
2024-12-25 00:37:50 +01:00
id: fileId,
userId: workspace.userId,
});
2024-12-30 21:50:08 +01:00
const { data: entry, isPending: isPendingEntry } = useQuery(
{
2024-12-30 21:50:08 +01:00
type: 'entry_get',
entryId: file?.entryId ?? '',
userId: workspace.userId,
},
{
enabled: !!file,
}
);
2024-12-30 21:50:08 +01:00
const { data: root, isPending: isPendingRoot } = useQuery(
{
type: 'entry_get',
entryId: file?.rootId ?? '',
userId: workspace.userId,
},
{
enabled: !!file,
}
);
if (isPendingFile || isPendingEntry || isPendingRoot) {
return null;
}
if (!file || !entry || !root) {
return null;
}
2024-12-30 21:50:08 +01:00
const role = extractEntryRole(root, workspace.userId);
if (!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-30 21:50:08 +01:00
<FileHeader file={file} role={role} entry={entry} />
2024-11-12 11:12:26 +01:00
<FileBody file={file} />
</div>
);
};