| 1 | import { useState } from "react";
|
| 2 | import { ScrollView, View } from "react-native";
|
| 3 | import { ScreenLayout } from "@/components/ui/ScreenLayout";
|
| 4 | import { Section, SectionHeader } from "@/components/ui/Sections";
|
| 5 | import { FilterPills } from "@/components/ui/FilterPills";
|
| 6 | import { useAuth } from "@/context/AuthContext";
|
| 7 | import { useHistoryFeed } from "@/hooks/useHistoryFeed";
|
| 8 | import type { HistoryCard, HistoryCategory } from "@/lib/history/types";
|
| 9 | import { MoodHistoryCard } from "@/components/history/MoodHistoryCard";
|
| 10 | import { SleepRecordCard } from "@/components/history/SleepRecordCard";
|
| 11 | import { TriggerHistoryCard } from "@/components/history/TriggerCard";
|
| 12 | import { MedicineHistoryCard } from "@/components/history/MedicineHistoryCard";
|
| 13 | import { AppointmentHistoryCard } from "@/components/history/AppointmentHistoryCard";
|
| 14 | import { ActivityHistoryCard } from "@/components/history/ActivityHistoryCard";
|
| 15 | import { EmptyState } from "@/components/ui/EmptyState";
|
| 16 |
|
| 17 | function HistoryCardRenderer({ card }: { card: HistoryCard }) {
|
| 18 | switch (card.category) {
|
| 19 | case "mood":
|
| 20 | return <MoodHistoryCard card={card} />;
|
| 21 | case "sleep":
|
| 22 | return <SleepRecordCard card={card} />;
|
| 23 | case "trigger":
|
| 24 | return <TriggerHistoryCard card={card} />;
|
| 25 | case "care_action":
|
| 26 | switch (card.subtype) {
|
| 27 | case "medicine":
|
| 28 | return <MedicineHistoryCard card={card} />;
|
| 29 | case "appointment":
|
| 30 | return <AppointmentHistoryCard card={card} />;
|
| 31 | case "activity":
|
| 32 | return <ActivityHistoryCard card={card} />;
|
| 33 | default:
|
| 34 | return null;
|
| 35 | }
|
| 36 | }
|
| 37 | }
|
| 38 |
|
| 39 | export default function History() {
|
| 40 | const { user } = useAuth();
|
| 41 | const [activeFilter, setActiveFilter] = useState<HistoryCategory | "all">(
|
| 42 | "all",
|
| 43 | );
|
| 44 | const grouped = useHistoryFeed(activeFilter);
|
| 45 |
|
| 46 | return (
|
| 47 | <ScreenLayout
|
| 48 | userName={user?.firstName}
|
| 49 | userAvatar={user?.avatarURL}
|
| 50 | >
|
| 51 | <ScrollView testID="history-list">
|
| 52 | <FilterPills active={activeFilter} onChange={setActiveFilter} />
|
| 53 |
|
| 54 | {Object.keys(grouped).length === 0 ? (
|
| 55 | <EmptyState
|
| 56 | title="Nenhum registro encontrado"
|
| 57 | subtitle="Tente mudar o filtro ou adicione um novo registro."
|
| 58 | icon="time-outline"
|
| 59 | />
|
| 60 | ) : (
|
| 61 | Object.entries(grouped).map(([date, cards]) => (
|
| 62 | <Section key={date}>
|
| 63 | <SectionHeader title={date} />
|
| 64 | <View>
|
| 65 | {cards.map((card) => (
|
| 66 | <HistoryCardRenderer key={card.id} card={card} />
|
| 67 | ))}
|
| 68 | </View>
|
| 69 | </Section>
|
| 70 | ))
|
| 71 | )}
|
| 72 | </ScrollView>
|
| 73 | </ScreenLayout>
|
| 74 | );
|
| 75 | }
|