2024-10-23 18:33:49 +02:00
|
|
|
import { useWorkspace } from '@/renderer/contexts/workspace';
|
|
|
|
|
import { useQuery } from '@/renderer/hooks/use-query';
|
|
|
|
|
import { FilePreview } from '@/renderer/components/files/file-preview';
|
|
|
|
|
import { FileSidebar } from '@/renderer/components/files/file-sidebar';
|
2024-10-24 08:56:36 +02:00
|
|
|
import { Button } from '@/renderer/components/ui/button';
|
2024-10-27 09:14:09 +01:00
|
|
|
import { SquareArrowOutUpRight } from 'lucide-react';
|
2024-10-30 10:00:54 +01:00
|
|
|
import { FileDownload } from '@/renderer/components/files/file-download';
|
|
|
|
|
import { getFileUrl } from '@/lib/files';
|
2024-10-23 18:33:49 +02:00
|
|
|
|
|
|
|
|
interface FileContainerProps {
|
|
|
|
|
nodeId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileContainer = ({ nodeId }: FileContainerProps) => {
|
|
|
|
|
const workspace = useWorkspace();
|
|
|
|
|
const { data } = useQuery({
|
|
|
|
|
type: 'file_get',
|
|
|
|
|
userId: workspace.userId,
|
|
|
|
|
fileId: nodeId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 10:00:54 +01:00
|
|
|
const url = getFileUrl(workspace.userId, data.id, data.extension);
|
2024-10-23 18:33:49 +02:00
|
|
|
return (
|
|
|
|
|
<div className="flex h-full max-h-full w-full flex-row items-center gap-2">
|
2024-10-24 08:56:36 +02:00
|
|
|
<div className="flex h-full max-h-full w-full max-w-full flex-grow flex-col items-center justify-center overflow-hidden">
|
|
|
|
|
<div className="mr-2 flex w-full flex-row justify-end gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
window.neuron.openFile(workspace.userId, data.id, data.extension)
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-10-27 09:14:09 +01:00
|
|
|
<SquareArrowOutUpRight className="mr-1 size-4" /> Open
|
2024-10-24 08:56:36 +02:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex w-full max-w-full flex-grow items-center justify-center overflow-hidden">
|
2024-10-30 10:00:54 +01:00
|
|
|
{data.downloadProgress !== 100 ? (
|
|
|
|
|
<FileDownload
|
|
|
|
|
id={data.id}
|
|
|
|
|
downloadProgress={data.downloadProgress}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<FilePreview url={url} name={data.name} mimeType={data.mimeType} />
|
|
|
|
|
)}
|
2024-10-24 08:56:36 +02:00
|
|
|
</div>
|
2024-10-23 18:33:49 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="h-full w-72 min-w-72 overflow-hidden border-l border-gray-100 p-2 pl-3">
|
|
|
|
|
<FileSidebar file={data} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|