import { useAdmin } from "../components/AdminSession"; import usePortfolioResource from "../usePortfolioResource"; import { ContentActions, DeleteContentDialog, ExperienceEditor } from "../components/PortfolioEditors"; import { useMemo, useState } from "react"; import { deleteExperience, getExperience } from "../api"; import Icon from "../components/Icon"; import PageHeader from "../components/PageHeader"; import { ErrorState, LoadingState } from "../components/Status"; function asDate(value) { const [year, month] = value.split("-").map(Number); return new Date(year, month - 1, 1); } function monthLabel(value) { return new Intl.DateTimeFormat("en-US", { month: "short", year: "numeric", }).format(asDate(value)); } function durationLabel(start, end) { const startDate = asDate(start); const endDate = end ? asDate(end) : new Date(); const months = Math.max( 1, (endDate.getFullYear() - startDate.getFullYear()) * 12 + endDate.getMonth() - startDate.getMonth(), ); const years = Math.floor(months / 12); const remainingMonths = months % 12; const parts = []; if (years) parts.push(`${years} yr${years === 1 ? "" : "s"}`); if (remainingMonths) parts.push(`${remainingMonths} mo`); return parts.join(" ") || "1 mo"; } function TimelineItem({ item, index, isExpanded, onToggle, actions }) { const isCurrent = !item.end; const year = item.start.slice(0, 4); return (
{actions}

{item.summary}

{item.highlights.length > 0 &&
    {item.highlights.map((highlight) => (
  • {highlight}
  • ))}
} {item.projects?.length > 0 && (
{item.projects.map((project) => ( {project.name} {project.period} ))}
)} {item.technologies.length > 0 &&
{item.technologies.map((technology) => ( {technology} ))}
}
); } export default function ExperiencePage() { const { isAdmin } = useAdmin(); const { data, loading, error, reload, setData } = usePortfolioResource(getExperience); const experience = data ?? []; const [expandedId, setExpandedId] = useState("independent"); const [editor, setEditor] = useState(null); function saved(record) { setData((current) => [...current.filter((item) => item.id !== record.id), record].sort((a, b) => b.start.localeCompare(a.start))); setExpandedId(record.id); setEditor(null); } const visibleYears = useMemo(() => { if (!experience.length) return "Your timeline"; return `${experience.at(-1).start.slice(0, 4)} — now`; }, [experience]); return (
{experience.length} career chapters
{visibleYears}
} /> {isAdmin &&

Keep your career timeline up to date.

} {loading && !data && } {error && } {data && (
{!experience.length &&

No experience entries yet.

} {experience.map((item, index) => ( setEditor({ kind: "edit", item })} onDelete={() => setEditor({ kind: "delete", item })} />} index={index} isExpanded={expandedId === item.id} item={item} key={item.id} onToggle={() => setExpandedId((active) => (active === item.id ? "" : item.id))} /> ))}
)} {editor?.kind === "edit" && setEditor(null)} onSaved={saved} />} {editor?.kind === "delete" && setEditor(null)} onDelete={(token) => deleteExperience(editor.item.id, token)} onDeleted={() => { setData((current) => current.filter((item) => item.id !== editor.item.id)); setEditor(null); }} />}
); }