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

4
import { Text } from "@/components/ui/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
import { DailySleepWidget } from "@/components/ui/DailySleepWidget";
30
import { EmptyState } from "@/components/ui/EmptyState";
31

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

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

43
  return (
44
    <ScreenLayout
45
      userName={user.firstName}
46
      userAvatar={user.avatarURL}
47
      showNotificationBadge={true}
48
    >
49
      <Section>
50
        <SectionHeader
51
          title="Como você está hoje?"
52
          subtitle="Sua jornada começa agora"
53
          testID="text-welcome-quick-register"
54
        ></SectionHeader>
55

56
        <Card style={{ minHeight: 200 }} testID="card-quick-register">
57
          <Col gap={16}>
58
            <Between style={styles.quickRegisterHeader}>
59
              <Text style={styles.quickRegisterTitle}>
60
                Registro rápido
61
              </Text>
62

63
              <Text style={styles.quickRegisterBadge}>HOJE</Text>
64
            </Between>
65

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

73
            <Button
74
              title="Salvar Humor"
75
              onPress={initQuickRegister}
76
              style={styles.quickRegisterButton}
77
              testID="button-save-mood"
78
            />
79
          </Col>
80
        </Card>
81
      </Section>
82

83
      {/* TODO: Check whether we gonna have to generate these on demand */}
84
      <Section>
85
        <SectionHeader title="Entre hoje e ontem" />
86

87
        <View
88
          style={[
89
            {
90
              flexDirection: "row",
91
              gap: 16,
92
            },
93
          ]}
94
        >
95
          <View style={{ flex: 1 }}>
96
            <DailyEnergyWidget />
97
          </View>
98

99
          <View style={{ flex: 1 }}>
100
            <DailySleepWidget />
101
          </View>
102
        </View>
103
      </Section>
104

105
      <Section>
106
        <SectionHeader title="Registros recentes" />
107

108
        {isLoading ? (
109
          <ActivityIndicator />
110
        ) : recentEntries.length === 0 ? (
111
          <EmptyState
112
            title="Nenhum registro ainda"
113
            subtitle="Seus registros de humor aparecerão aqui."
114
          />
115
        ) : (
116
          <Col gap={8}>
117
            {recentEntries.map((entry) => (
118
              <MoodEntryLog key={entry.id} entry={entry} />
119
            ))}
120
          </Col>
121
        )}
122
      </Section>
123
    </ScreenLayout>
124
  );
125
}
126

127
const styles = StyleSheet.create({
128
  quickRegisterHeader: {
129
    marginTop: 16,
130
    paddingLeft: 16,
131
    paddingRight: 16,
132
  },
133
  quickRegisterTitle: {
134
    ...Typography.bodyLg,
135
  },
136
  // TODO: Replace when we have badges
137
  quickRegisterBadge: {
138
    fontSize: 12,
139
    lineHeight: 16,
140
  },
141
  quickRegisterButton: {
142
    marginLeft: 16,
143
    marginRight: 16,
144
    marginBottom: 16,
145
    ...Shadows.lg,
146
  },
147
  lineTrack: {
148
    height: 6,
149
    backgroundColor: Colors.light.divider,
150
    borderRadius: BorderRadius.full,
151
    marginBottom: 4,
152
    overflow: "hidden",
153
  },
154
  lineFill: {
155
    height: "100%",
156
    backgroundColor: Colors.light.tint,
157
    borderRadius: BorderRadius.full,
158
  },
159
  indicatorGreen: {
160
    color: Colors.light.tint,
161
    fontSize: 11,
162
    fontWeight: 600,
163
    lineHeight: 16.5,
164
  },
165
});