import { useState, useCallback } from "react"; import { Sidebar } from "./components/Sidebar"; import type { View } from "./components/Sidebar"; import { MonthlyForm, YearEndForm } from "./components/PromptForm"; import { LetterView } from "./components/LetterView"; import { Welcome } from "./components/Welcome"; import { PodcastYearEndForm } from "./components/PodcastYearEnd"; import { Home } from "./components/Home"; import { AllYearsLetter } from "./components/AllYearsLetter"; import { load, save, getMonthlyEntry, upsertMonthlyEntry, getYearEndEntry, upsertYearEndEntry, getPodcastEntry, upsertPodcastEntry, } from "./utils/storage"; import type { AppData } from "./types"; const now = new Date(); const TODAY_YEAR = now.getFullYear(); const TODAY_MONTH = now.getMonth(); export default function App() { const [data, setData] = useState(load); const [view, setView] = useState({ kind: "home" }); const persist = useCallback((next: AppData) => { setData(next); save(next); }, []); function handleStart(name: string) { persist({ ...data, name }); } if (!data.name) { return ( ); } return (
{view.kind === "home" && ( )} {view.kind === "month" && ( { persist( upsertMonthlyEntry(data, { year: view.year, month: view.month, answers, completedAt: new Date().toISOString(), }) ); }} /> )} {view.kind === "yearEnd" && ( { persist( upsertYearEndEntry(data, { year: view.year, answers, completedAt: new Date().toISOString(), }) ); }} /> )} {view.kind === "letter" && ( )} {view.kind === "allYears" && ( )} {view.kind === "podcast" && ( { persist( upsertPodcastEntry(data, { year: view.year, podcastName, answers, completedAt: new Date().toISOString(), }) ); }} /> )}
); }