import { useEffect, useMemo, useState } from "react"; import { coverBackground } from "./constants.jsx"; /** * Asks which notebook something should go into. * * "All Notes", "Starred" and the dashboard are views, not places — a note * created while one of them is open has no notebook to belong to. The app used * to answer that silently with `notebooks[0]`, so a note or an imported PDF * landed in whichever notebook happened to sort first. Nothing was lost, but * finding it again meant knowing that rule. * * The last choice is remembered, so the common case — always the same notebook — * is one Enter away, while the answer stays visible instead of being guessed. */ const LAST_KEY = "inknote_last_notebook"; export const rememberNotebook = (id) => { try { localStorage.setItem(LAST_KEY, id); } catch { /* private mode: the default simply is not remembered */ } }; const recalledNotebook = () => { try { return localStorage.getItem(LAST_KEY); } catch { return null; } }; export function NotebookPicker({ notebooks, title, confirmLabel = "Continue", onPick, onClose, dark }) { const remembered = recalledNotebook(); const [selected, setSelected] = useState( () => notebooks.find((nb) => nb.id === remembered)?.id || notebooks[0]?.id || null ); const T = useMemo( () => ({ bg: dark ? "#161b22" : "#fff", border: dark ? "#30363d" : "#d0d7de", text: dark ? "#e6edf3" : "#1f2328", muted: dark ? "#8b949e" : "#656d76", accent: dark ? "#388bfd" : "#0969da", row: dark ? "#0d1117" : "#f6f8fa", }), [dark] ); useEffect(() => { const onKey = (e) => { if (e.key === "Escape") onClose(); if (e.key === "Enter" && selected) confirm(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }); const confirm = () => { if (!selected) return; rememberNotebook(selected); onPick(selected); }; return (
e.stopPropagation()} style={{ background: T.bg, borderRadius: 16, padding: 24, width: 400, maxWidth: "92vw", border: `1px solid ${T.border}`, boxShadow: "0 20px 40px rgba(0,0,0,0.3)", fontFamily: "'DM Sans',sans-serif", }} >
{title}
Which notebook should it go in?
{notebooks.map((nb) => { const active = nb.id === selected; return ( ); })}
); }