import { useState, useEffect } from "react"; import { PODCAST_PROMPTS } from "../types"; import { generatePodcastEmail } from "../utils/podcastEmailTemplate"; import type { PodcastYearEndEntry } from "../types"; interface PodcastFormProps { entry?: PodcastYearEndEntry; year: number; onSave: (podcastName: string, answers: Record) => void; } export function PodcastYearEndForm({ entry, year, onSave }: PodcastFormProps) { const [podcastName, setPodcastName] = useState(entry?.podcastName ?? ""); const [answers, setAnswers] = useState>( entry?.answers ?? {} ); const [view, setView] = useState<"form" | "email">("form"); const [copied, setCopied] = useState(false); const [saved, setSaved] = useState(false); useEffect(() => { setPodcastName(entry?.podcastName ?? ""); setAnswers(entry?.answers ?? {}); setView("form"); setSaved(false); }, [year, entry]); function handleSave() { onSave(podcastName, answers); setSaved(true); setTimeout(() => setSaved(false), 2000); } const filled = PODCAST_PROMPTS.filter((p) => answers[p.id]?.trim()).length; const previewEntry: PodcastYearEndEntry = { year, podcastName, answers, }; const email = generatePodcastEmail(previewEntry); function handleCopy() { navigator.clipboard.writeText(email).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); } function renderMarkdown(text: string): string { return text .split(/\n\n+/) .map((para) => { const inner = para .split("\n") .map((line) => line.replace(/\*\*(.+?)\*\*/g, "$1")) .join("
"); return `

${inner}

`; }) .join(""); } return (

Podcast Year-End Email — {year}

{view === "form" && ( {filled}/{PODCAST_PROMPTS.length} answered )}

Answer a few questions about your podcast year. The app will compile them into a ready-to-send listener email.

{view === "form" && ( <>
setPodcastName(e.target.value)} />
{PODCAST_PROMPTS.map((p) => (