import { useState, useEffect } from 'react'; import { api, Entry } from '../lib/api'; import EntryInput from '../components/EntryInput'; import EntryList from '../components/EntryList'; export default function Home() { const [entries, setEntries] = useState([]); const [loading, setLoading] = useState(true); const [generating, setGenerating] = useState(false); const today = new Date().toISOString().split('T')[0]; useEffect(() => { loadEntries(); }, []); const loadEntries = async () => { setLoading(true); const res = await api.getDay(today); if (res.data) { setEntries(res.data.entries); } setLoading(false); }; const handleAddEntry = async (type: string, content: string, metadata?: object) => { const res = await api.createEntry(today, type, content, metadata); if (res.data) { setEntries((prev) => [...prev, res.data!]); } return res; }; const handleDeleteEntry = async (id: string) => { const res = await api.deleteEntry(id); if (res.data) { setEntries((prev) => prev.filter((e) => e.id !== id)); } }; const handleGenerateJournal = async () => { setGenerating(true); await api.generateJournal(today); setGenerating(false); }; return (

Today

{new Date().toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' })}

{loading ? (
Loading...
) : entries.length === 0 ? (

No entries yet today

Start capturing your day above

) : ( )} {entries.length > 0 && (
View journal →
)}
); }