| 1 | import { useState } from "react";
|
| 2 | import { ScrollView, View, Text } 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 { 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 |
|
| 13 | const FILTERS: { label: string; value: HistoryCategory | "all" }[] = [
|
| 14 | { label: "Tudo", value: "all" },
|
| 15 | { label: "Humor", value: "mood" },
|
| 16 | { label: "Sono", value: "sleep" },
|
| 17 | { label: "Gatilho", value: "trigger" },
|
| 18 | ];
|
| 19 |
|
| 20 | function HistoryCardRenderer({ card }: { card: HistoryCard }) {
|
| 21 | switch (card.category) {
|
| 22 | case "mood":
|
| 23 | return <MoodHistoryCard card={card as any} />;
|
| 24 | case "sleep":
|
| 25 | return <SleepRecordCard card={card as any} />;
|
| 26 | case "trigger":
|
| 27 | return <TriggerHistoryCard card={card as any} />;
|
| 28 | }
|
| 29 | }
|
| 30 |
|
| 31 | export default function History() {
|
| 32 | const { user } = useAuth();
|
| 33 | const [activeFilter, setActiveFilter] = useState<HistoryCategory | "all">(
|
| 34 | "all",
|
| 35 | );
|
| 36 | const grouped = useHistoryFeed(activeFilter);
|
| 37 |
|
| 38 | return (
|
| 39 | <ScreenLayout
|
| 40 | userName={user.firstName}
|
| 41 | userAvatar={user.avatarURL}
|
| 42 | onNotificationPress={() => console.log("Notifications")}
|
| 43 | showNotificationBadge={true}
|
| 44 | >
|
| 45 | <ScrollView>
|
| 46 | <FilterPills active={activeFilter} onChange={setActiveFilter} />
|
| 47 |
|
| 48 | {Object.entries(grouped).map(([date, cards]) => (
|
| 49 | <Section key={date}>
|
| 50 | <SectionHeader title={date} />
|
| 51 | <View>
|
| 52 | {cards.map((card) => (
|
| 53 | <HistoryCardRenderer key={card.id} card={card} />
|
| 54 | ))}
|
| 55 | </View>
|
| 56 | </Section>
|
| 57 | ))}
|
| 58 | </ScrollView>
|
| 59 | </ScreenLayout>
|
| 60 | );
|
| 61 | }
|