import { Modal, Button, SimpleGrid, FileButton } from "@mantine/core"; import { IconCheck, IconFileCode, IconMarkdown, IconX, } from "@tabler/icons-react"; import { importPage } from "@/features/page/services/page-service.ts"; import { notifications } from "@mantine/notifications"; import { treeDataAtom } from "@/features/page/tree/atoms/tree-data-atom.ts"; import { useAtom } from "jotai"; import { buildTree } from "@/features/page/tree/utils"; import { IPage } from "@/features/page/types/page.types.ts"; import React from "react"; interface PageImportModalProps { spaceId: string; open: boolean; onClose: () => void; } export default function PageImportModal({ spaceId, open, onClose, }: PageImportModalProps) { return ( <> Import pages ); } interface ImportFormatSelection { spaceId: string; onClose: () => void; } function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) { const [treeData, setTreeData] = useAtom(treeDataAtom); const handleFileUpload = async (selectedFiles: File[]) => { if (!selectedFiles) { return; } onClose(); const alert = notifications.show({ title: "Importing pages", message: "Page import is in progress. Please do not close this tab.", loading: true, autoClose: false, }); const pages: IPage[] = []; let pageCount = 0; for (const file of selectedFiles) { try { const page = await importPage(file, spaceId); pages.push(page); pageCount += 1; } catch (err) { console.log("Failed to import page", err); } } if (pages?.length > 0 && pageCount > 0) { const newTreeNodes = buildTree(pages); const fullTree = treeData.concat(newTreeNodes); if (newTreeNodes?.length && fullTree?.length > 0) { setTreeData(fullTree); } const pageCountText = pageCount === 1 ? "1 page" : `${pageCount} pages`; notifications.update({ id: alert, color: "teal", title: `Successfully imported ${pageCountText}`, message: "Your import is complete.", icon: , loading: false, autoClose: 5000, }); } else { notifications.update({ id: alert, color: "red", title: `Failed to import pages`, message: "Unable to import pages. Please try again.", icon: , loading: false, autoClose: 5000, }); } }; return ( <> {(props) => ( )} {(props) => ( )} ); }