import { useRef } from "react"; import { COVER_PALETTES } from "../model/book"; import { useBook } from "../store/useBook"; import { CoverArt } from "./CoverArt"; import { Icon } from "./Icon"; function readImage(file: File): Promise { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result as string); reader.onerror = reject; reader.readAsDataURL(file); }); } export function CoverView() { const book = useBook((s) => s.book); const setCover = useBook((s) => s.setCover); const fileRef = useRef(null); if (!book) return null; const cover = book.cover; const upload = async (file: File) => { const image = await readImage(file); setCover({ kind: "image", image }); }; return (
{cover.kind === "image" ? ( <>

Your artwork fills the cover as-is.

) : ( <>
{COVER_PALETTES.map((p) => ( ))}

Title, subtitle & author are set in Book setup.

)} { const file = e.target.files?.[0]; if (file) upload(file); e.currentTarget.value = ""; }} />
); }