2025-06-20 17:51:24 +01:00
|
|
|
import React, { useState, useCallback } from "react";
|
|
|
|
import { Box, Group, Container } from "@mantine/core";
|
|
|
|
import TopControls from "../components/shared/TopControls";
|
2025-06-19 22:41:05 +01:00
|
|
|
import FileManager from "../components/fileManagement/FileManager";
|
2025-06-20 17:51:24 +01:00
|
|
|
import FileEditor from "../components/editor/FileEditor";
|
2025-06-19 22:41:05 +01:00
|
|
|
import PageEditor from "../components/editor/PageEditor";
|
|
|
|
import PageEditorControls from "../components/editor/PageEditorControls";
|
|
|
|
import Viewer from "../components/viewer/Viewer";
|
2025-06-20 17:51:24 +01:00
|
|
|
import FileUploadSelector from "../components/shared/FileUploadSelector";
|
2025-05-27 19:22:26 +01:00
|
|
|
|
2025-05-21 21:47:44 +01:00
|
|
|
export default function HomePage() {
|
2025-06-20 17:51:24 +01:00
|
|
|
const [files, setFiles] = useState([]); // Array of { file, url }
|
|
|
|
const [preSelectedFiles, setPreSelectedFiles] = useState([]);
|
|
|
|
const [currentView, setCurrentView] = useState("fileManager");
|
2025-05-27 19:22:26 +01:00
|
|
|
const [sidebarsVisible, setSidebarsVisible] = useState(true);
|
2025-06-20 17:51:24 +01:00
|
|
|
const [downloadUrl, setDownloadUrl] = useState(null);
|
|
|
|
const [pageEditorFunctions, setPageEditorFunctions] = useState(null);
|
2025-05-21 21:47:44 +01:00
|
|
|
|
2025-06-20 17:51:24 +01:00
|
|
|
// Handle file selection from upload
|
|
|
|
const handleFileSelect = useCallback((file) => {
|
|
|
|
const fileObj = { file, url: URL.createObjectURL(file) };
|
|
|
|
setFiles([fileObj]);
|
2025-06-18 14:16:39 +01:00
|
|
|
}, []);
|
|
|
|
|
2025-06-20 17:51:24 +01:00
|
|
|
// Handle opening file editor with selected files
|
|
|
|
const handleOpenFileEditor = useCallback((selectedFiles) => {
|
|
|
|
setPreSelectedFiles(selectedFiles || []);
|
|
|
|
setCurrentView("fileEditor");
|
|
|
|
}, []);
|
2025-05-21 21:47:44 +01:00
|
|
|
|
|
|
|
return (
|
2025-05-28 21:43:02 +01:00
|
|
|
<Group
|
|
|
|
align="flex-start"
|
|
|
|
gap={0}
|
2025-06-06 17:20:06 +01:00
|
|
|
className="min-h-screen w-screen overflow-hidden flex-nowrap flex"
|
2025-05-28 21:43:02 +01:00
|
|
|
>
|
2025-06-20 17:51:24 +01:00
|
|
|
<Box
|
2025-06-18 18:12:15 +01:00
|
|
|
className="flex-1 h-screen min-w-80 relative flex flex-col"
|
2025-06-20 17:51:24 +01:00
|
|
|
style={{
|
2025-06-18 18:12:15 +01:00
|
|
|
backgroundColor: 'var(--bg-background)'
|
|
|
|
}}
|
2025-06-18 14:16:39 +01:00
|
|
|
>
|
2025-06-05 21:59:18 +01:00
|
|
|
{/* Top Controls */}
|
|
|
|
<TopControls
|
|
|
|
currentView={currentView}
|
|
|
|
setCurrentView={setCurrentView}
|
|
|
|
/>
|
2025-05-28 21:43:02 +01:00
|
|
|
{/* Main content area */}
|
2025-06-20 17:51:24 +01:00
|
|
|
<Box className="flex-1 min-h-0 margin-top-200 relative z-10">
|
|
|
|
{currentView === "fileManager" ? (
|
|
|
|
<FileManager
|
|
|
|
files={files}
|
|
|
|
setFiles={setFiles}
|
|
|
|
setCurrentView={setCurrentView}
|
|
|
|
onOpenFileEditor={handleOpenFileEditor}
|
|
|
|
/>
|
|
|
|
) : (currentView !== "fileManager") && !files[0] ? (
|
|
|
|
<Container size="lg" p="xl" h="100%" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
|
<FileUploadSelector
|
|
|
|
title={currentView === "viewer" ? "Select a PDF to view" : "Select a PDF to edit"}
|
|
|
|
subtitle="Choose a file from storage or upload a new PDF"
|
|
|
|
sharedFiles={files}
|
|
|
|
onFileSelect={handleFileSelect}
|
|
|
|
allowMultiple={false}
|
|
|
|
accept={["application/pdf"]}
|
|
|
|
loading={false}
|
2025-05-27 19:22:26 +01:00
|
|
|
/>
|
2025-06-20 17:51:24 +01:00
|
|
|
</Container>
|
|
|
|
) : currentView === "fileEditor" ? (
|
|
|
|
<FileEditor
|
|
|
|
sharedFiles={files}
|
|
|
|
setSharedFiles={setFiles}
|
|
|
|
preSelectedFiles={preSelectedFiles}
|
|
|
|
onClearPreSelection={() => setPreSelectedFiles([])}
|
|
|
|
onOpenPageEditor={(file) => {
|
|
|
|
const fileObj = { file, url: URL.createObjectURL(file) };
|
|
|
|
setFiles([fileObj]);
|
|
|
|
setCurrentView("pageEditor");
|
|
|
|
}}
|
|
|
|
onMergeFiles={(filesToMerge) => {
|
|
|
|
setFiles(filesToMerge.map(f => ({ file: f, url: URL.createObjectURL(f) })));
|
|
|
|
setCurrentView("viewer");
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : currentView === "viewer" ? (
|
|
|
|
<Viewer
|
|
|
|
pdfFile={files[0]}
|
|
|
|
setPdfFile={(fileObj) => setFiles([fileObj])}
|
|
|
|
sidebarsVisible={sidebarsVisible}
|
|
|
|
setSidebarsVisible={setSidebarsVisible}
|
|
|
|
/>
|
|
|
|
) : currentView === "pageEditor" ? (
|
|
|
|
<>
|
|
|
|
<PageEditor
|
|
|
|
file={files[0]}
|
|
|
|
setFile={(fileObj) => setFiles([fileObj])}
|
|
|
|
downloadUrl={downloadUrl}
|
|
|
|
setDownloadUrl={setDownloadUrl}
|
|
|
|
onFunctionsReady={setPageEditorFunctions}
|
|
|
|
sharedFiles={files}
|
2025-05-27 19:22:26 +01:00
|
|
|
/>
|
2025-06-20 17:51:24 +01:00
|
|
|
{files[0] && pageEditorFunctions && (
|
|
|
|
<PageEditorControls
|
|
|
|
onClosePdf={pageEditorFunctions.closePdf}
|
|
|
|
onUndo={pageEditorFunctions.handleUndo}
|
|
|
|
onRedo={pageEditorFunctions.handleRedo}
|
|
|
|
canUndo={pageEditorFunctions.canUndo}
|
|
|
|
canRedo={pageEditorFunctions.canRedo}
|
|
|
|
onRotate={pageEditorFunctions.handleRotate}
|
|
|
|
onDelete={pageEditorFunctions.handleDelete}
|
|
|
|
onSplit={pageEditorFunctions.handleSplit}
|
|
|
|
onExportSelected={() => pageEditorFunctions.showExportPreview(true)}
|
|
|
|
onExportAll={() => pageEditorFunctions.showExportPreview(false)}
|
|
|
|
exportLoading={pageEditorFunctions.exportLoading}
|
|
|
|
selectionMode={pageEditorFunctions.selectionMode}
|
|
|
|
selectedPages={pageEditorFunctions.selectedPages}
|
2025-06-19 19:47:44 +01:00
|
|
|
/>
|
2025-06-20 17:51:24 +01:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<FileManager
|
|
|
|
files={files}
|
|
|
|
setFiles={setFiles}
|
|
|
|
setCurrentView={setCurrentView}
|
|
|
|
onOpenFileEditor={handleOpenFileEditor}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
2025-05-21 21:47:44 +01:00
|
|
|
</Box>
|
|
|
|
</Group>
|
|
|
|
);
|
|
|
|
}
|