import { useCallback, useEffect, useState } from 'react'; import { Activity, Armchair, Bell, CalendarCheck, Droplet, Footprints, Pill, type LucideIcon, } from 'lucide-react'; import { api, ApiError } from '../api/client'; import { useAuth } from '../auth/AuthContext'; import { usePatient } from '../lib/usePatient'; import { useAutoRefresh } from '../lib/useAutoRefresh'; import { BindPatient } from '../components/BindPatient'; import type { Reminder } from '../api/types'; import { formatTime, reminderLabel } from '../lib/format'; import './RemindersPage.css'; const TYPE_ICON: Record = { measurement: Activity, water: Droplet, exercise: Footprints, rest: Armchair, checkup: CalendarCheck, medication: Pill, }; export function RemindersPage(): JSX.Element { const { boundPatientId } = useAuth(); const { patient, loading, reload } = usePatient(); const [reminders, setReminders] = useState([]); const [err, setErr] = useState(null); const load = useCallback(() => { if (!boundPatientId) return; api .listReminders(boundPatientId) .then((list) => setReminders([...list].reverse())) .catch((e) => setErr(e instanceof ApiError ? e.message : '加载提醒失败')); }, [boundPatientId]); useEffect(() => { load(); }, [load]); // 多端一致:管理师下发提醒近实时出现 useAutoRefresh(load); if (!boundPatientId || (!patient && !loading)) { return (

先绑定孕妇

); } return (

关怀提醒

{patient ? `${patient.name} 的孕期提醒,方便你协助陪伴。` : ''}

{err &&

{err}

} {reminders.length === 0 ? (

暂无提醒。

) : ( reminders.map((r) => { const Icon = TYPE_ICON[r.effectiveType] ?? Bell; return (

{reminderLabel(r.effectiveType)} {r.adjustedForRisk && 已为她调整}

{r.message}

{formatTime(r.scheduledAt)}

); }) )}
); }