eletrotupi / tcc/ frontend/app/(tabs)/new/index.tsx58fc6edcba4ecd00dfece8d7b69e529d18da9ae5
4.9 KB | 182 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
import { DailyEnergyWidget } from "@/components/ui/DailyEnergyWidget";
29

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

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

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

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

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

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

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

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

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

86
      {/* TODO: Check whether we gonna have to generate these on demand */}
87
      <Section>
88
        <View
89
          style={[
90
            {
91
              flexDirection: "row",
92
              gap: 16,
93
            },
94
          ]}
95
        >
96
          <View style={{ flex: 1 }}>
97
            <DailyEnergyWidget />
98
          </View>
99

100
          <View style={{ flex: 1 }}>
101
            <Card style={{ padding: Spacing.cardGap }}>
102
              <View
103
                style={{
104
                  flex: 1,
105
                  flexDirection: "row",
106
                  flexGrow: 0,
107
                  paddingVertical: 10,
108
                }}
109
              >
110
                <Ionicons name="moon" size={20} color="#64748B" />
111

112
                <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
113
                  Sono
114
                </Text>
115
              </View>
116

117
              <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
118
                7h 30m
119
              </Text>
120

121
              <Text style={styles.indicatorGreen}>+45min que ontem</Text>
122
            </Card>
123
          </View>
124
        </View>
125
      </Section>
126

127
      <Section>
128
        <SectionHeader title="Registros recentes" />
129

130
        {isLoading ? (
131
          <ActivityIndicator />
132
        ) : (
133
          <Col gap={8}>
134
            {recentEntries.map((entry) => (
135
              <MoodEntryLog key={entry.id} entry={entry} />
136
            ))}
137
          </Col>
138
        )}
139
      </Section>
140
    </ScreenLayout>
141
  );
142
}
143

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