eletrotupi / tcc/ frontend/app/(tabs)/new/entry.tsx168d22498bb1eb151e34366b5620c81f53768e83
4.7 KB | 170 lines Raw
1
import { useState, useEffect } from 'react';
2
import {
3
  Link, router, useLocalSearchParams
4
} from 'expo-router';
5

6
import {
7
  View,
8
  Text,
9
  StyleSheet,
10
  ScrollView
11
} from 'react-native';
12

13
import { SafeAreaView } from 'react-native-safe-area-context';
14
import { ThemedText } from '@/components/misc/themed-text';
15
import { ThemedView } from '@/components/misc/themed-view';
16
import { ScreenLayout } from '@/components/ui/ScreenLayout';
17
import { useAuth } from '@/context/AuthContext';
18
import { Grid, Col, Row, Between, Center } from '@/components/ui/LayoutHelpers';
19
import { Card } from '@/components/ui/Cards';
20
import { Button } from '@/components/ui/Button';
21
import { Input, TextArea } from '@/components/ui/Input';
22
import { Section, SectionHeader } from '@/components/ui/Sections';
23
import { Spacing, Typography, Colors } from '@/constants/theme';
24
import { ScaleSlider } from '@/components/ui/ScaleSlider';
25
import { MoodComponentCard } from '@/components/ui/MoodComponentCard';
26
import { Ionicons } from '@expo/vector-icons';
27
import { useThemeColor } from '@/hooks/use-theme-color';
28
import {
29
  useMoodEntryStore,
30
} from '@/stores/moodEntry';
31

32
import {
33
  MOODS,
34
  getMood
35
} from '@/constants/moods';
36

37
export default function NewMoodEntry() {
38
  const { user } = useAuth();
39
  const tintColor = useThemeColor({}, 'tint');
40

41
  const { initialMood } = useLocalSearchParams();
42
  const [stress, setStress] = useState(0);
43
  const [anxiety, setAnxiety] = useState(0);
44
  const [energy, setEnergy] = useState(0);
45

46
  const {
47
    selectedMood,
48
    setSelectedMood,
49
    components,
50
    reset
51
  } = useMoodEntryStore();
52

53
  useEffect(() => {
54
    setSelectedMood(getMood(initialMood));
55
  }, [initialMood]);
56

57
  useEffect(() => {
58
    return () => reset();
59
  }, []);
60

61
  const editComponents = () => {
62
    router.push("/entry/mood-components")
63
  }
64

65
  return (
66
    <View>
67
      <ScrollView
68
        scrollEventThrottle={16}>
69
        <View style={styles.container}>
70
          <Center>
71
            <ThemedText style={styles.statusPrefix}>
72
              Como você está se sentindo agora?
73
            </ThemedText>
74

75
            <ThemedText style={styles.statusText}>
76
              {selectedMood?.label || "Neutro"}
77
            </ThemedText>
78
          </Center>
79

80
          <Card style={styles.resumeCard}>
81
            <Col gap={24}>
82
              <ScaleSlider
83
                variant="rich"
84
                label="Energia"
85
                value={energy}
86
                onValueChange={setEnergy}
87
                icon={<Ionicons name="flower-outline" size={20} color={tintColor} />}
88
                minLabel="Baixa"
89
                maxLabel="Alta"
90
              />
91

92
              <ScaleSlider
93
                variant="rich"
94
                label="Ansiedade"
95
                value={anxiety}
96
                onValueChange={setAnxiety}
97
                icon={<Ionicons name="sad-outline" size={20} color="#FB923C" />}
98
                minLabel="Calmo"
99
                maxLabel="Ansioso"
100
              />
101

102
              <ScaleSlider
103
                variant="rich"
104
                label="Estresse"
105
                value={stress}
106
                onValueChange={setStress}
107
                icon={<Ionicons name="flame" size={20} color="#f87171" />}
108
                minLabel="Relaxado"
109
                maxLabel="Estressado"
110
              />
111
            </Col>
112
          </Card>
113

114
          <Card style={styles.annotationsCard}>
115
            <TextArea
116
              label="Notas sobre o dia"
117
              type="text"
118
              variant="darkGhost"
119
              onChangeText={(val) => console.log(val)}
120
              minRows={4}
121
              maxRows={6}
122
              placeholder="Escreva uma nota rápida sobre o seu dia até o momento..."
123
            />
124
          </Card>
125

126
          <Section>
127
            <SectionHeader title="Componentes do Humor" info="Editar" />
128
            {components.length > 0 ? (
129
              <Grid gap={2} style={{ marginTop: 8 }}>
130
                {components.map((comp) => (
131
                  <MoodComponentCard
132
                    key={comp.id}
133
                    id={comp.id}
134
                    intensity={comp.intensity}
135
                  />
136
                ))}
137
              </Grid>
138
            ) : null}
139

140
            <Button title="Adicionar Componentes"
141
              onPress={editComponents}
142
              textStyle={{ fontWeight: 500 }}
143
              variant="dashed"
144
            />
145
          </Section>
146
        </View>
147
      </ScrollView>
148
    </View>
149
  );
150
}
151

152
const styles = StyleSheet.create({
153
  container: {
154
    gap: 24,
155
    paddingHorizontal: Spacing.containerPadding,
156
    paddingVertical: Spacing.sectionGap,
157
  },
158
  statusText: {
159
    ...Typography.headlineXg,
160
  },
161
  statusPrefix: {
162
    ...Typography.bodyMd
163
  },
164
  annotationsCard: {
165
    padding: Spacing.cardGap
166
  },
167
  resumeCard: {
168
    padding: Spacing.cardGap,
169
  }
170
});