frontend: guard the trigger detail timer and optional links
Pedro Lucas Porcellis porcellis@eletrotupi.com · 12 days ago
c6faa4c901e5f6c4ca8395c08d412ed57e708f6a Browse filesParents
ceec194Changed files
1
Additions
+5
Deletions
-7
frontend/app/triggers/[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 -
import { Col, Between, Row } from "@/components/ui/LayoutHelpers";
16 +
import { Col, Row } from "@/components/ui/LayoutHelpers";
19 17
import { Section, SectionHeader } from "@/components/ui/Sections";
20 18
import { Theme, Typography, Colors, Spacing } from "@/constants/theme";
21 19
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
22 20
import { getTriggerCategory } from "@/constants/trigger-categories";
23 21
import { getCareActionMeta } from "@/constants/care-action-categories";
48 46
const [minutesLeft, setMinutesLeft] = useState(0);
49 47
const [canDelete, setCanDelete] = useState(false);
50 48
51 49
useEffect(() => {
52 50
const updateTimer = () => {
53 -
const createdAt = new Date(trigger?.createdAt);
54 -
if (!createdAt) return;
51 +
if (!trigger?.createdAt) return;
52 +
const createdAt = new Date(trigger.createdAt);
55 53
56 54
const msSinceCreation = Date.now() - createdAt.getTime();
57 55
const deletionWindowMs = 5 * 60 * 1000;
58 56
59 57
const newCanDelete = msSinceCreation < deletionWindowMs;
172 170
{/* Linked moods */}
173 171
<Section>
174 172
<SectionHeader title="Vínculo" variant="subtle" />
175 173
{!!hasAnyLinks ? (
176 174
<Col gap={8}>
177 -
{trigger.moodLinks.map((link) => {
175 +
{(trigger.moodLinks ?? []).map((link) => {
178 176
const moodDef = getMood(link.mood.selectedMood.toLowerCase());
179 177
return (
180 178
<Pressable
181 179
key={link.id}
182 180
onPress={() => router.push(`/entry/${link.mood.id}`)}
438 436
impactFill: {
439 437
height: "100%",
440 438
borderRadius: 99,
441 439
},
442 440
});