import { useEffect, useRef } from "react"; import { Input, TextArea } from "../../commons"; import useToggle from "../../helpers/hooks/useToggle"; import PageToolbar from "./PageToolbar"; import "./Cover.css"; import "./Page.css"; function Page({ page, setPage, removePage, restorePage, deletedPages }) { const [isTitleEditable, setIsTitleEditable] = useToggle(); const [isBodyEditable, setIsBodyEditable] = useToggle(); const inputRef = useRef(null); const textareaRef = useRef(null); const isCover = () => page && page.id === 0; const is404 = () => page && page.id === null; useEffect(() => { inputRef.current && inputRef.current.focus(); textareaRef.current && textareaRef.current.focus(); }); const handleSubmit = (e) => { e.preventDefault(); }; const handleOnChange = (e) => { let newValue = {}; switch (e.target.name) { case "notebook-title": newValue = { title: e.target.value }; break; case "notebook-body": newValue = { body: e.target.value }; break; default: break; } setPage((previous) => { return { ...previous, ...newValue }; }); }; return (
{!isTitleEditable && (

{ if (!is404()) setIsTitleEditable(); }} > {page.title}

)} {isTitleEditable && (
)}
{!isBodyEditable && (
{ if (!is404()) setIsBodyEditable(); }} > {page.body}
)} {isBodyEditable && (