import type { NextPage } from "next"; import { useContext, useEffect, useRef, useState } from "react"; import asciidoctor from "asciidoctor"; 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"; //import Link from "next/link"; const ProjectModal: NextPage = () => { const [visible, setVisible] = useState(false); const [diaryPages, setDiaryPages] = useState([]); const [content, setContent] = useState(projectEmpty); const setModalContent = async (content: Project|Diary, selectedPage?: number) => { if (content.type === "diary") setDiaryPages(content.entries.map(entry => entry.title)); setContent(await generateContent(content, selectedPage)); }; const { updateCallbacks: updateCmdCallbacks } = useCommands(); const { updateCallbacks: updateModalCallbacks } = useModalFunctions(); updateCmdCallbacks({ setModalVisible: setVisible, setModalContent}); updateModalCallbacks({ setVisible, setContent: setModalContent, setHtml: setContent }); const containerRef = useRef(null); useEffect(() => { if (content && containerRef.current) { containerRef.current.innerHTML = content; } }, [content]); if (!visible) return <>; return
setVisible(false)}>
X
{ // TODO // If diaryPages // Show page selector }
; }; export default ProjectModal;