frontend: tidy the mood detail screen after the cast cleanup
Pedro Lucas Porcellis porcellis@eletrotupi.com · 12 days ago
ceec19494f8065b22d45311703c93bbf20f546ca Browse filesParents
ea14755Changed files
1
Additions
+6
Deletions
-14
frontend/app/entry/[id].tsx
1 -
import { useState, useEffect, use } from "react";
1 +
import { useState, useEffect } from "react";
2 2
import {
3 3
StyleSheet,
4 4
View,
5 5
ScrollView,
6 6
Pressable,
7 7
ActivityIndicator,
8 8
} from "react-native";
9 9
import { Text } from "@/components/ui/Text";
10 10
import { useLocalSearchParams, router, Stack } from "expo-router";
11 -
import { format } from "date-fns";
12 -
import { ptBR } from "date-fns/locale";
13 11
14 12
import { Card, SubtleInfoCard } from "@/components/ui/Cards";
15 13
import { NoLinkMessage } from "@/components/misc/NoLinkMessage";
16 14
import { Badge } from "@/components/ui/Badge";
17 15
import { Button } from "@/components/ui/Button";
18 16
import { Col, Between, Row } from "@/components/ui/LayoutHelpers";
19 17
import { Section, SectionHeader } from "@/components/ui/Sections";
20 18
import { Theme, Colors, Spacing } from "@/constants/theme";
21 19
import { getMood } from "@/constants/moods";
22 -
import {
23 -
getMoodComponent,
24 -
intensityLabel,
25 -
intensityToValue,
26 -
} from "@/constants/mood-components";
27 20
import { useMoodEntry, useDeleteMoodEntry } from "@/hooks";
28 -
import { getTimeBadge, formatMoment } from "@/lib/utils/time";
21 +
import { formatMoment } from "@/lib/utils/time";
29 22
import { MoodComponentCard } from "@/components/ui/MoodComponentCard";
30 23
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
31 24
import { getTriggerCategory } from "@/constants/trigger-categories";
32 25
import { getCareActionMeta } from "@/constants/care-action-categories";
33 26
46 39
const [minutesLeft, setMinutesLeft] = useState(0);
47 40
const [canDelete, setCanDelete] = useState(false);
48 41
49 42
useEffect(() => {
50 43
const updateTimer = () => {
51 -
const moment = new Date(entry?.moment);
52 -
const createdAt = new Date(entry?.moment);
44 +
if (!entry?.moment) return;
45 +
const createdAt = new Date(entry.moment);
53 46
const msSinceCreation = Date.now() - createdAt.getTime();
54 47
const deletionWindowMs = 5 * 60 * 1000;
55 48
56 49
const newCanDelete = msSinceCreation < deletionWindowMs;
57 50
const newMinutesLeft = Math.max(
89 82
);
90 83
}
91 84
92 85
const moment = new Date(entry.moment);
93 86
const moodDef = getMood(entry.selectedMood.toLowerCase());
94 -
const badge = getTimeBadge(moment);
95 87
96 88
const handleDelete = async () => {
97 89
await deleteMoodEntry.mutateAsync(String(entry.id));
98 90
99 91
router.back();
142 134
<SectionHeader title="Níveis emocionais" variant="subtle" />
143 135
{[
144 136
{ id: "energy", label: "Energia", value: entry.energyLevel },
145 137
{ id: "stress", label: "Estresse", value: entry.stressLevel },
146 138
{ id: "anxiety", label: "Ansiedade", value: entry.anxietyLevel },
147 -
].map((item, index, arr) => (
139 +
].map((item) => (
148 140
<Card key={item.id} style={{ padding: Spacing.cardGap }}>
149 141
<View key={item.label}>
150 142
<View style={styles.componentRow}>
151 143
<Text style={styles.componentLabel}>{item.label}</Text>
152 144
<Text style={styles.componentIntensityGreen}>
185 177
{/* Linked triggers */}
186 178
<Section>
187 179
<SectionHeader title="Vínculo" variant="subtle" />
188 180
{!!hasAnyLinks ? (
189 181
<Col gap={8}>
190 -
{entry.triggerLinks.map((link) => {
182 +
{(entry.triggerLinks ?? []).map((link) => {
191 183
const cat = getTriggerCategory(link.trigger.category);
192 184
return (
193 185
<Pressable
194 186
key={link.id}
195 187
onPress={() => router.push(`/triggers/${link.trigger.id}`)}
435 427
height: "100%",
436 428
borderRadius: 99,
437 429
},
438 430
439 431
});