eletrotupi / tcc/ commit / ad95ceb

frontend: show the active badge only on the latest mood entry

The badge rendered on every entry's detail screen. It now compares the
entry against the newest one from the list, so it only marks the most
recent record
Pedro Lucas Porcellis porcellis@eletrotupi.com · 12 days ago ad95ceb1d7d44db7a364485d77c18e8e3c2a4392 Browse files
Parents 9e81281
Changed files
1
Additions
+4
Deletions
-2
frontend/app/entry/[id].tsx
1 1
import { useState, useEffect } from "react";
2 2
import {
3 3
  StyleSheet,
4 4
  View,
5 5
  ScrollView,
15 15
import { Button } from "@/components/ui/Button";
16 16
import { Col, Between, Row } from "@/components/ui/LayoutHelpers";
17 17
import { Section, SectionHeader } from "@/components/ui/Sections";
18 18
import { Theme, Colors, Spacing } from "@/constants/theme";
19 19
import { getMood } from "@/constants/moods";
20 -
import { useMoodEntry, useDeleteMoodEntry } from "@/hooks";
20 +
import { useMoodEntry, useMoodEntries, useDeleteMoodEntry } from "@/hooks";
21 21
import { formatMoment } from "@/lib/utils/time";
22 22
import { MoodComponentCard } from "@/components/ui/MoodComponentCard";
23 23
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
24 24
import { getTriggerCategory } from "@/constants/trigger-categories";
25 25
import { getCareActionMeta } from "@/constants/care-action-categories";
33 33
};
34 34

35 35
export default function MoodDetailScreen() {
36 36
  const { id } = useLocalSearchParams<{ id: string }>();
37 37
  const { data: entry, isLoading, isError } = useMoodEntry(id);
38 +
  const { data: latestEntries } = useMoodEntries({ limit: 1 });
38 39
  const deleteMoodEntry = useDeleteMoodEntry();
39 40
  const [minutesLeft, setMinutesLeft] = useState(0);
40 41
  const [canDelete, setCanDelete] = useState(false);
41 42

42 43
  useEffect(() => {
82 83
    );
83 84
  }
84 85

85 86
  const moment = new Date(entry.moment);
86 87
  const moodDef = getMood(entry.selectedMood.toLowerCase());
88 +
  const isLatestEntry = latestEntries?.entries[0]?.id === entry.id;
87 89

88 90
  const handleDelete = async () => {
89 91
    await deleteMoodEntry.mutateAsync(String(entry.id));
90 92

91 93
    router.back();
123 125
                </Text>
124 126
                <Text style={styles.moodTime}>{formatMoment(moment)}</Text>
125 127
              </Col>
126 128
            </Row>
127 129
            {/* If this is the latest mood entry, show the active badge */}
128 -
            <Badge label="Registro Ativo" variant="green" />
130 +
            {isLatestEntry && <Badge label="Registro Ativo" variant="green" />}
129 131
          </Between>
130 132
        </Card>
131 133

132 134
        {/* Core levels */}
133 135
        <Section>
427 429
    height: "100%",
428 430
    borderRadius: 99,
429 431
  },
430 432

431 433
});