import { useId, useState } from 'react' import { Dialog } from '#/components/dialog' import { Button } from '#/components/ui/button' import { Checkbox } from '#/components/ui/checkbox' import { Input } from '#/components/ui/input' import { SidebarInset, SidebarProvider } from '#/components/ui/sidebar' import { Textarea } from '#/components/ui/textarea' import { TooltipProvider } from '#/components/ui/tooltip' import { WorkspaceNavigation } from '#/components/workspace-navigation' import './journal.css' type EntryKind = 'メモ' | '再開地点' | '服薬' | '体重' type Entry = { id: string kind: EntryKind text: string source: string occurredAt: string recordedAt: string correctionOf?: string } type Draft = Pick const emptyDraft: Draft = { kind: 'メモ', text: '', source: '', occurredAt: '' } const kinds: EntryKind[] = ['メモ', '再開地点', '服薬', '体重'] function formatTime(value: string | undefined) { if (!value) return '不明' return new Date(value).toLocaleString('ja-JP', { year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit', }) } export function JournalPage() { const [entries, setEntries] = useState([]) const [draft, setDraft] = useState(emptyDraft) const [correcting, setCorrecting] = useState(null) const [reviewing, setReviewing] = useState(false) const [selected, setSelected] = useState>(new Set()) const superseded = new Set(entries.map((entry) => entry.correctionOf)) const current = entries.filter((entry) => !superseded.has(entry.id)) function append(value: Draft, correctionOf?: string) { setEntries((previous) => [ { ...value, text: value.text.trim(), source: value.source.trim(), id: crypto.randomUUID(), recordedAt: new Date().toISOString(), correctionOf, }, ...previous, ]) } return (

記録

{ append(draft) setDraft(emptyDraft) }} submitLabel="記録する" />
{entries.length === 0 && (

まだ記録はありません

)} {entries.map((entry) => (
{entry.kind} {superseded.has(entry.id) && ( 訂正前 )} {entry.correctionOf && ( 訂正 )} {!superseded.has(entry.id) && ( )}

{entry.text} {entry.kind === '体重' ? ' kg' : ''}

発生日時: {formatTime(entry.occurredAt)} · 記録日時:{' '} {formatTime(entry.recordedAt)}

{(entry.kind === '体重' || entry.source) && (

記録元: {entry.source || '不明'}

)}
))}
{correcting && ( setCorrecting(null)} onSave={(value) => { append(value, correcting.id) setCorrecting(null) }} /> )} {reviewing && ( setReviewing(false)} >

含める記録を選んで確認できます。外部には送信されません。

{current.map((entry) => ( ))}