import type { NextPage } from "next"; import { useRef, useState } from "react"; import styles from "../styles/ProjectModal.module.css"; import type { Project, Diary } from "../lib/content/types"; import { useCommands } from "./contexts/CommandInterface"; import { generateContent, projectEmpty } from "../lib/content/generate"; import { useModalFunctions } from "./contexts/ModalFunctions"; const ProjectModal: NextPage = () => { const [visible, setVisible] = useState(false); const [currentContent, setCurrentContent] = useState(undefined); const [currentPage, setCurrentPage] = useState(0); const [HTMLContent, setHTMLContent] = useState(projectEmpty); const setModalContent = async (content: Project | Diary, selectedPage?: number) => { setCurrentContent(content); if (content.type === "diary") setCurrentPage(selectedPage === undefined ? 0 : selectedPage); setHTMLContent(await generateContent(content, selectedPage)); }; const { updateCallbacks: updateCmdCallbacks } = useCommands(); const { updateCallbacks: updateModalCallbacks } = useModalFunctions(); updateCmdCallbacks({ setModalVisible: setVisible, setModalContent, setModalHTML: setHTMLContent }); updateModalCallbacks({ setVisible, setContent: setModalContent, setHtml: setHTMLContent }); const containerRef = useRef(null); if (!visible) return <>; const nextPageSelector = (() => { if (!currentContent || currentContent?.type !== "diary" || currentContent.entries.length === 0) return null; const prev = {currentPage > 0 ? setModalContent(currentContent, currentPage - 1)}>< {currentPage - 1 > 0 ? currentContent.entries[currentPage - 2].title : "Main page"} : null}; const next = {currentPage < currentContent.entries.length ? setModalContent(currentContent, currentPage + 1)}>{currentContent.entries[currentPage].title} > : null}; const select = ( ); return
{prev}{currentPage > 0 ?   |   : null}{select}{currentPage < currentContent.entries.length ?   |   : null}{next}
; })(); return
setVisible(false)}>
X
{nextPageSelector}
{nextPageSelector}
; }; export default ProjectModal;