eletrotupi / tcc/ frontend/app/(tabs)/history.tsx9897f0373a757f09dbe54e9fae5842f71c99703d
2.7 KB | 76 lines Raw
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
      showNotificationBadge={true}
51
    >
52
      <ScrollView testID="history-list">
53
        <FilterPills active={activeFilter} onChange={setActiveFilter} />
54

55
        {Object.keys(grouped).length === 0 ? (
56
          <EmptyState
57
            title="Nenhum registro encontrado"
58
            subtitle="Tente mudar o filtro ou adicione um novo registro."
59
            icon="time-outline"
60
          />
61
        ) : (
62
          Object.entries(grouped).map(([date, cards]) => (
63
            <Section key={date}>
64
              <SectionHeader title={date} />
65
              <View>
66
                {cards.map((card) => (
67
                  <HistoryCardRenderer key={card.id} card={card} />
68
                ))}
69
              </View>
70
            </Section>
71
          ))
72
        )}
73
      </ScrollView>
74
    </ScreenLayout>
75
  );
76
}