frontend: align the new entry screen with the store and api types
Pedro Lucas Porcellis porcellis@eletrotupi.com · 12 days ago
16a7e33e5e723f45548ed5cc1b9959317ff3a683 Browse filesParents
de30833Changed files
1
Additions
+11
Deletions
-19
frontend/app/(tabs)/new/entry.tsx
1 1
import { useState, useEffect } from "react";
2 -
import { Link, router, useLocalSearchParams } from "expo-router";
2 +
import { router, useLocalSearchParams } from "expo-router";
3 3
4 4
import { View, StyleSheet, ScrollView } from "react-native";
5 5
6 6
import { Text } from "@/components/ui/Text";
7 -
import { SafeAreaView } from "react-native-safe-area-context";
8 -
import { ThemedView } from "@/components/misc/themed-view";
9 -
import { ScreenLayout } from "@/components/ui/ScreenLayout";
10 -
import { useAuth } from "@/context/AuthContext";
11 -
import { Grid, Col, Row, Between, Center } from "@/components/ui/LayoutHelpers";
7 +
import { Grid, Col, Center } from "@/components/ui/LayoutHelpers";
12 8
import { Card } from "@/components/ui/Cards";
13 9
import { Button } from "@/components/ui/Button";
14 -
import { Input, TextArea } from "@/components/ui/Input";
10 +
import { TextArea } from "@/components/ui/Input";
15 11
import { Section, SectionHeader } from "@/components/ui/Sections";
16 12
import { Spacing, Typography, Colors } from "@/constants/theme";
17 13
import { ScaleSlider } from "@/components/ui/ScaleSlider";
18 14
import { MoodComponentCard } from "@/components/ui/MoodComponentCard";
19 15
import { Ionicons } from "@expo/vector-icons";
20 16
import { useThemeColor, useCreateMoodEntry, usePatchCareAction } from "@/hooks";
21 17
import { useMoodEntryStore, useCareActionLinkStore } from "@/stores";
22 18
23 -
import { MOODS, getMood } from "@/constants/moods";
19 +
import { getMood } from "@/constants/moods";
24 20
25 21
import { intensityToValue } from "@/constants/mood-components";
26 22
27 -
import { apiClient } from "@/lib/api";
28 -
29 23
export default function NewMoodEntry() {
30 -
const { user } = useAuth();
31 24
const tintColor = useThemeColor({}, "tint");
32 25
33 -
const { initialMood } = useLocalSearchParams();
34 -
const [annotation, setAnnotation] = useState();
26 +
const { initialMood } = useLocalSearchParams<{ initialMood?: string }>();
27 +
const [annotation, setAnnotation] = useState('');
35 28
const [stress, setStress] = useState(0);
36 29
const [anxiety, setAnxiety] = useState(0);
37 30
const [energy, setEnergy] = useState(0);
38 31
39 32
const { selectedMood, setSelectedMood, components, reset } =
41 34
42 35
const createMoodEntry = useCreateMoodEntry();
43 36
const patchCareAction = usePatchCareAction();
44 37
45 38
useEffect(() => {
46 -
if (initialMood) setSelectedMood(getMood(initialMood));
47 -
}, [initialMood]);
39 +
if (initialMood) setSelectedMood(initialMood);
40 +
}, [initialMood, setSelectedMood]);
48 41
49 42
useEffect(() => {
50 43
return () => reset();
51 -
}, []);
44 +
}, [reset]);
52 45
53 46
const saveMoodEntry = async () => {
54 47
const data = {
55 -
selectedMood: selectedMood?.id.toUpperCase(),
48 +
selectedMood: (selectedMood ?? 'neutral').toUpperCase(),
56 49
stressLevel: stress,
57 50
energyLevel: energy,
58 51
anxietyLevel: anxiety,
59 52
moment: new Date(),
60 53
annotation: annotation,
92 85
<Text style={styles.statusPrefix} testID="text-status-prefix">
93 86
Como você está se sentindo agora?
94 87
</Text>
95 88
96 89
<Text style={styles.statusText}>
97 -
{selectedMood?.label || "Neutro"}
90 +
{getMood(selectedMood ?? '')?.label ?? "Neutro"}
98 91
</Text>
99 92
</Center>
100 93
101 94
<Card style={styles.resumeCard}>
102 95
<Text style={styles.infoText}>
141 134
</Card>
142 135
143 136
<Card style={styles.annotationsCard}>
144 137
<TextArea
145 138
label="Notas sobre o dia"
146 -
type="text"
147 139
variant="darkGhost"
148 140
onChangeText={(val) => setAnnotation(val)}
149 141
value={annotation}
150 142
minRows={4}
151 143
maxRows={6}
213 205
},
214 206
resumeCard: {
215 207
padding: Spacing.cardGap,
216 208
},
217 209
});