frontend: create mood entry :)
Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago
bc4e3ca8a4a1a26c0509b5e4a1bc22853f463bd2 Browse filesParents
cd9c2c3Changed files
1
Additions
+34
Deletions
-1
frontend/app/(tabs)/new/entry.tsx
1 1
import { useState, useEffect } from 'react';
2 2
import {
3 3
Link, router, useLocalSearchParams
4 4
} from 'expo-router';
5 5
32 32
import {
33 33
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);
45 54
46 55
const {
56 65
57 66
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
}
64 92
65 93
return (
114 142
<Card style={styles.annotationsCard}>
115 143
<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..."
123 152
/>
124 153
</Card>
141 170
onPress={editComponents}
142 171
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>
149 182
);
150 183
}
166 199
},
167 200
resumeCard: {
168 201
padding: Spacing.cardGap,
169 202
}
170 203
});