| 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 | return (
|
| 43 | <ScreenLayout
|
| 44 | userName={user.firstName}
|
| 45 | userAvatar={user.avatarURL}
|
| 46 | onNotificationPress={() => console.log("Notifications")}
|
| 47 | showNotificationBadge={true}
|
| 48 | >
|
| 49 | <Section>
|
| 50 | <SectionHeader
|
| 51 | title="Como você está hoje?"
|
| 52 | subtitle="Sua jornada começa agora"
|
| 53 | ></SectionHeader>
|
| 54 |
|
| 55 | <Card style={{ minHeight: 200 }}>
|
| 56 | <Col gap={16}>
|
| 57 | <Between style={styles.quickRegisterHeader}>
|
| 58 | <ThemedText style={styles.quickRegisterTitle}>
|
| 59 | Registro rápido
|
| 60 | </ThemedText>
|
| 61 |
|
| 62 | <ThemedText style={styles.quickRegisterBadge}>HOJE</ThemedText>
|
| 63 | </Between>
|
| 64 |
|
| 65 | <MoodSelector
|
| 66 | style={{ paddingLeft: 8, paddingRight: 8, paddingTop: 16 }}
|
| 67 | items={MOODS}
|
| 68 | value={mood}
|
| 69 | onSelect={setMood}
|
| 70 | />
|
| 71 |
|
| 72 | <Button
|
| 73 | title="Salvar Humor"
|
| 74 | onPress={initQuickRegister}
|
| 75 | style={styles.quickRegisterButton}
|
| 76 | />
|
| 77 | </Col>
|
| 78 | </Card>
|
| 79 | </Section>
|
| 80 |
|
| 81 | {/* TODO: Check whether we gonna have to generate these on demand */}
|
| 82 | <Section>
|
| 83 | <Grid gap={4}>
|
| 84 | <Card style={{ padding: Spacing.cardGap }}>
|
| 85 | <View
|
| 86 | style={{
|
| 87 | flex: 1,
|
| 88 | flexDirection: "row",
|
| 89 | flexGrow: 0,
|
| 90 | paddingVertical: 10,
|
| 91 | }}
|
| 92 | >
|
| 93 | <Ionicons name="flash" size={20} color="#64748B" />
|
| 94 |
|
| 95 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 96 | Energia
|
| 97 | </Text>
|
| 98 | </View>
|
| 99 |
|
| 100 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 101 | Média Alta
|
| 102 | </Text>
|
| 103 |
|
| 104 | <View style={styles.lineTrack}>
|
| 105 | <View style={[styles.lineFill, { width: `35%` }]} />
|
| 106 | </View>
|
| 107 | </Card>
|
| 108 |
|
| 109 | <Card style={{ padding: Spacing.cardGap }}>
|
| 110 | <View
|
| 111 | style={{
|
| 112 | flex: 1,
|
| 113 | flexDirection: "row",
|
| 114 | flexGrow: 0,
|
| 115 | paddingVertical: 10,
|
| 116 | }}
|
| 117 | >
|
| 118 | <Ionicons name="moon-outline" size={20} color="#64748B" />
|
| 119 |
|
| 120 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 121 | Sono
|
| 122 | </Text>
|
| 123 | </View>
|
| 124 |
|
| 125 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 126 | 7h 30m
|
| 127 | </Text>
|
| 128 |
|
| 129 | <Text style={styles.indicatorGreen}>+45min que ontem</Text>
|
| 130 | </Card>
|
| 131 | </Grid>
|
| 132 | </Section>
|
| 133 |
|
| 134 | <Section>
|
| 135 | <SectionHeader title="Registros recentes" />
|
| 136 |
|
| 137 | {isLoading ? (
|
| 138 | <ActivityIndicator />
|
| 139 | ) : (
|
| 140 | <Col gap={8}>
|
| 141 | {recentEntries.map((entry) => (
|
| 142 | <MoodEntryLog key={entry.id} entry={entry} />
|
| 143 | ))}
|
| 144 | </Col>
|
| 145 | )}
|
| 146 | </Section>
|
| 147 | </ScreenLayout>
|
| 148 | );
|
| 149 | }
|
| 150 |
|
| 151 | const styles = StyleSheet.create({
|
| 152 | quickRegisterHeader: {
|
| 153 | marginTop: 16,
|
| 154 | paddingLeft: 16,
|
| 155 | paddingRight: 16,
|
| 156 | },
|
| 157 | quickRegisterTitle: {
|
| 158 | ...Typography.bodyLg,
|
| 159 | },
|
| 160 | // TODO: Replace when we have badges
|
| 161 | quickRegisterBadge: {
|
| 162 | fontSize: 12,
|
| 163 | lineHeight: 16,
|
| 164 | },
|
| 165 | quickRegisterButton: {
|
| 166 | marginLeft: 16,
|
| 167 | marginRight: 16,
|
| 168 | marginBottom: 16,
|
| 169 | ...Shadows.lg,
|
| 170 | },
|
| 171 | lineTrack: {
|
| 172 | height: 6,
|
| 173 | backgroundColor: Colors.light.divider,
|
| 174 | borderRadius: BorderRadius.full,
|
| 175 | marginBottom: 4,
|
| 176 | overflow: "hidden",
|
| 177 | },
|
| 178 | lineFill: {
|
| 179 | height: "100%",
|
| 180 | backgroundColor: Colors.light.tint,
|
| 181 | borderRadius: BorderRadius.full,
|
| 182 | },
|
| 183 | indicatorGreen: {
|
| 184 | color: Colors.light.tint,
|
| 185 | fontSize: 11,
|
| 186 | fontWeight: 600,
|
| 187 | lineHeight: 16.5,
|
| 188 | },
|
| 189 | });
|