eletrotupi / tcc/ frontend/app/(tabs)/new/index.tsx6a5c371ce1221ee4c61aa0cb3c665e3793580dc3
4.5 KB | 165 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
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
  console.log("entries: ", data, recentEntries);
39

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

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

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

64
              <ThemedText style={styles.quickRegisterBadge}>HOJE</ThemedText>
65
            </Between>
66

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

74
            <Button
75
              title="Salvar Humor"
76
              onPress={initQuickRegister}
77
              style={styles.quickRegisterButton}
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
});