eletrotupi / tcc/ frontend/app/(tabs)/new/index.tsxbf66e8068e516afcd5f94a3c9b17c031f0ed8335
5.2 KB | 193 lines Raw
1
import { useEffect, useState } from "react";
2
import { StyleSheet, View, Text, ActivityIndicator } from "react-native";
3

4
import { ThemedText } from "@/components/misc/themed-text";
5
import { ThemedView } from "@/components/misc/themed-view";
6
import { ScreenLayout } from "@/components/ui/ScreenLayout";
7
import { useAuth } from "@/context/AuthContext";
8
import { Grid, Col, Row, Between } from "@/components/ui/LayoutHelpers";
9
import { Card } from "@/components/ui/Cards";
10
import { Badge } from "@/components/ui/Badge";
11
import { Button } from "@/components/ui/Button";
12
import { Section, SectionHeader } from "@/components/ui/Sections";
13
import { MoodSelector } from "@/components/ui/EmojiSelectors";
14
import {
15
  Typography,
16
  Spacing,
17
  Shadows,
18
  Colors,
19
  BorderRadius,
20
} from "@/constants/theme";
21
import { Ionicons } from "@expo/vector-icons";
22
import { router } from "expo-router";
23
import { MoodDefinition, MOODS } from "@/constants/moods";
24

25
import { useThemeColor, useMoodEntries } from "@/hooks";
26

27
import MoodEntryLog from "@/components/ui/MoodEntryLog";
28

29
export default function New() {
30
  const { user } = useAuth();
31
  const [mood, setMood] = useState<string>("good");
32
  const { data, isLoading } = useMoodEntries({ limit: 5 });
33
  const recentEntries = data?.entries ?? [];
34

35
  console.log("entries: ", data, recentEntries);
36

37
  const initQuickRegister = () => {
38
    // TODO: Set down on camelCase vs kebab case
39
    router.navigate(`/new/entry?initialMood=${mood}`);
40
  };
41

42
  const onNotificationPress = () => {
43
    router.push('/notifications');
44
  }
45

46
  return (
47
    <ScreenLayout
48
      userName={user.firstName}
49
      userAvatar={user.avatarURL}
50
      onNotificationPress={onNotificationPress}
51
      showNotificationBadge={true}
52
    >
53
      <Section>
54
        <SectionHeader
55
          title="Como você está hoje?"
56
          subtitle="Sua jornada começa agora"
57
        ></SectionHeader>
58

59
        <Card style={{ minHeight: 200 }}>
60
          <Col gap={16}>
61
            <Between style={styles.quickRegisterHeader}>
62
              <ThemedText style={styles.quickRegisterTitle}>
63
                Registro rápido
64
              </ThemedText>
65

66
              <ThemedText style={styles.quickRegisterBadge}>HOJE</ThemedText>
67
            </Between>
68

69
            <MoodSelector
70
              style={{ paddingLeft: 8, paddingRight: 8, paddingTop: 16 }}
71
              items={MOODS}
72
              value={mood}
73
              onSelect={setMood}
74
            />
75

76
            <Button
77
              title="Salvar Humor"
78
              onPress={initQuickRegister}
79
              style={styles.quickRegisterButton}
80
            />
81
          </Col>
82
        </Card>
83
      </Section>
84

85
      {/* TODO: Check whether we gonna have to generate these on demand */}
86
      <Section>
87
        <Grid gap={4}>
88
          <Card style={{ padding: Spacing.cardGap }}>
89
            <View
90
              style={{
91
                flex: 1,
92
                flexDirection: "row",
93
                flexGrow: 0,
94
                paddingVertical: 10,
95
              }}
96
            >
97
              <Ionicons name="flash" size={20} color="#64748B" />
98

99
              <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
100
                Energia
101
              </Text>
102
            </View>
103

104
            <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
105
              Média Alta
106
            </Text>
107

108
            <View style={styles.lineTrack}>
109
              <View style={[styles.lineFill, { width: `35%` }]} />
110
            </View>
111
          </Card>
112

113
          <Card style={{ padding: Spacing.cardGap }}>
114
            <View
115
              style={{
116
                flex: 1,
117
                flexDirection: "row",
118
                flexGrow: 0,
119
                paddingVertical: 10,
120
              }}
121
            >
122
              <Ionicons name="moon-outline" size={20} color="#64748B" />
123

124
              <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
125
                Sono
126
              </Text>
127
            </View>
128

129
            <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
130
              7h 30m
131
            </Text>
132

133
            <Text style={styles.indicatorGreen}>+45min que ontem</Text>
134
          </Card>
135
        </Grid>
136
      </Section>
137

138
      <Section>
139
        <SectionHeader title="Registros recentes" />
140

141
        {isLoading ? (
142
          <ActivityIndicator />
143
        ) : (
144
          <Col gap={8}>
145
            {recentEntries.map((entry) => (
146
              <MoodEntryLog key={entry.id} entry={entry} />
147
            ))}
148
          </Col>
149
        )}
150
      </Section>
151
    </ScreenLayout>
152
  );
153
}
154

155
const styles = StyleSheet.create({
156
  quickRegisterHeader: {
157
    marginTop: 16,
158
    paddingLeft: 16,
159
    paddingRight: 16,
160
  },
161
  quickRegisterTitle: {
162
    ...Typography.bodyLg,
163
  },
164
  // TODO: Replace when we have badges
165
  quickRegisterBadge: {
166
    fontSize: 12,
167
    lineHeight: 16,
168
  },
169
  quickRegisterButton: {
170
    marginLeft: 16,
171
    marginRight: 16,
172
    marginBottom: 16,
173
    ...Shadows.lg,
174
  },
175
  lineTrack: {
176
    height: 6,
177
    backgroundColor: Colors.light.divider,
178
    borderRadius: BorderRadius.full,
179
    marginBottom: 4,
180
    overflow: "hidden",
181
  },
182
  lineFill: {
183
    height: "100%",
184
    backgroundColor: Colors.light.tint,
185
    borderRadius: BorderRadius.full,
186
  },
187
  indicatorGreen: {
188
    color: Colors.light.tint,
189
    fontSize: 11,
190
    fontWeight: 600,
191
    lineHeight: 16.5,
192
  },
193
});