frontend: create mood entry :)
Parents:
cd9c2c31 file(s) changed
- frontend/app/(tabs)/new/entry.tsx +34 -1
frontend/app/(tabs)/new/entry.tsx
@@ -34,11 +34,20 @@ MOODS,
34 34 getMood
35 35 } from '@/constants/moods';
36 36
37 + import {
38 + intensityToValue
39 + } from '@/constants/mood-components';
40 +
41 + import {
42 + apiClient
43 + } from '@/lib/api';
44 +
37 45 export default function NewMoodEntry() {
38 46 const { user } = useAuth();
39 47 const tintColor = useThemeColor({}, 'tint');
40 48
41 49 const { initialMood } = useLocalSearchParams();
50 + const [annotation, setAnnotation] = useState();
42 51 const [stress, setStress] = useState(0);
43 52 const [anxiety, setAnxiety] = useState(0);
44 53 const [energy, setEnergy] = useState(0);
@@ -58,6 +67,25 @@ useEffect(() => {
58 67 return () => reset();
59 68 }, []);
60 69
70 + const saveMoodEntry = async () => {
71 + const data = {
72 + selectedMood: selectedMood?.id.toUpperCase(),
73 + stressLevel: stress,
74 + energyLevel: energy,
75 + anxietyLevel: anxiety,
76 + moment: new Date(),
77 + annotation: annotation,
78 + moodComponents: components.map((c) => ({
79 + component: c.id.toUpperCase(),
80 + intensity: intensityToValue(c.intensity)
81 + }))
82 + }
83 +
84 + const result = await apiClient.createMoodEntry(data)
85 +
86 + router.push("/")
87 + }
88 +
61 89 const editComponents = () => {
62 90 router.push("/entry/mood-components")
63 91 }
@@ -116,7 +144,8 @@ <TextArea
116 144 label="Notas sobre o dia"
117 145 type="text"
118 146 variant="darkGhost"
119 - onChangeText={(val) => console.log(val)}
147 + onChangeText={(val) => setAnnotation(val)}
148 + value={annotation}
120 149 minRows={4}
121 150 maxRows={6}
122 151 placeholder="Escreva uma nota rápida sobre o seu dia até o momento..."
@@ -143,6 +172,10 @@ textStyle={{ fontWeight: 500 }}
143 172 variant="dashed"
144 173 />
145 174 </Section>
175 +
176 + <Button title="Salvar Registro"
177 + onPress={saveMoodEntry}
178 + />
146 179 </View>
147 180 </ScrollView>
148 181 </View>