refactor: PDF editor

This commit is contained in:
Ibrahima G. Coulibaly
2025-07-10 15:30:45 +01:00
parent 65574872ae
commit 92c0249534

View File

@@ -6,45 +6,16 @@ import { ToolComponentProps } from '@tools/defineTool';
import { EmbedPDF } from '@simplepdf/react-embed-pdf'; import { EmbedPDF } from '@simplepdf/react-embed-pdf';
export default function PdfEditor({ title }: ToolComponentProps) { export default function PdfEditor({ title }: ToolComponentProps) {
const [input, setInput] = useState<File | null>(null);
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
const onFileChange = (file: File | null) => {
if (file) {
setInput(file);
const url = URL.createObjectURL(file);
setPdfUrl(url);
} else {
setInput(null);
setPdfUrl(null);
}
};
return ( return (
<ToolContent <ToolContent
title={title} title={title}
initialValues={{}} initialValues={{}}
getGroups={null} getGroups={null}
input={input} input={null}
inputComponent={ inputComponent={
<>
{pdfUrl ? (
<Box sx={{ width: '100%', height: '80vh' }}> <Box sx={{ width: '100%', height: '80vh' }}>
<EmbedPDF <EmbedPDF mode="inline" style={{ width: '100%', height: '100%' }} />
mode="inline"
style={{ width: '100%', height: '100%' }}
documentURL={pdfUrl}
/>
</Box> </Box>
) : (
<ToolPdfInput
value={input}
onChange={onFileChange}
accept={['application/pdf']}
title="Upload a PDF to edit"
/>
)}
</>
} }
toolInfo={{ toolInfo={{
title: 'PDF Editor', title: 'PDF Editor',