| 1 | import { useEffect, useState } from 'react';
|
| 2 | import {
|
| 3 | StyleSheet,
|
| 4 | View,
|
| 5 | Text,
|
| 6 | ActivityIndicator
|
| 7 | } from 'react-native';
|
| 8 |
|
| 9 | import { ThemedText } from '@/components/misc/themed-text';
|
| 10 | import { ThemedView } from '@/components/misc/themed-view';
|
| 11 | import { ScreenLayout } from '@/components/ui/ScreenLayout';
|
| 12 | import { useAuth } from '@/context/AuthContext';
|
| 13 | import { Grid, Col, Row, Between } from '@/components/ui/LayoutHelpers';
|
| 14 | import { Card } from '@/components/ui/Cards';
|
| 15 | import { Badge } from '@/components/ui/Badge';
|
| 16 | import { Button } from '@/components/ui/Button';
|
| 17 | import { Section, SectionHeader } from '@/components/ui/Sections';
|
| 18 | import { MoodSelector } from '@/components/ui/EmojiSelectors';
|
| 19 | import { Typography, Spacing, Shadows, Colors, BorderRadius } from '@/constants/theme';
|
| 20 | import { Ionicons } from '@expo/vector-icons';
|
| 21 | import { router } from 'expo-router';
|
| 22 | import {
|
| 23 | MoodDefinition, MOODS
|
| 24 | } from '@/constants/moods'
|
| 25 |
|
| 26 | import {
|
| 27 | useThemeColor,
|
| 28 | useMoodEntries
|
| 29 | } from '@/hooks';
|
| 30 |
|
| 31 | import MoodEntryLog from '@/components/ui/MoodEntryLog';
|
| 32 |
|
| 33 | export default function New() {
|
| 34 | const { user } = useAuth();
|
| 35 | const [mood, setMood] = useState<string>('good');
|
| 36 | const { data, isLoading } = useMoodEntries({ limit: 5 });
|
| 37 | const recentEntries = data?.entries ?? [];
|
| 38 |
|
| 39 | console.log("entries: ", data, recentEntries)
|
| 40 |
|
| 41 | const initQuickRegister = () => {
|
| 42 | // TODO: Set down on camelCase vs kebab case
|
| 43 | router.navigate(`/new/entry?initialMood=${mood}`)
|
| 44 | };
|
| 45 |
|
| 46 | return (
|
| 47 | <ScreenLayout userName={user.firstName} userAvatar={user.avatarURL}
|
| 48 | onNotificationPress={() => console.log('Notifications')}
|
| 49 | showNotificationBadge={true}>
|
| 50 | <Section>
|
| 51 | <SectionHeader
|
| 52 | title="Como você está hoje?"
|
| 53 | subtitle="Sua jornada começa agora"
|
| 54 | >
|
| 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}>
|
| 65 | HOJE
|
| 66 | </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 style={{ flex: 1, flexDirection: 'row', flexGrow: 0, paddingVertical: 10 }}>
|
| 90 | <Ionicons name="flash" size={20} color="#64748B" />
|
| 91 |
|
| 92 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 93 | Energia
|
| 94 | </Text>
|
| 95 | </View>
|
| 96 |
|
| 97 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 98 | Média Alta
|
| 99 | </Text>
|
| 100 |
|
| 101 | <View style={styles.lineTrack}>
|
| 102 | <View style={[styles.lineFill, { width: `35%` }]} />
|
| 103 | </View>
|
| 104 | </Card>
|
| 105 |
|
| 106 | <Card style={{ padding: Spacing.cardGap }}>
|
| 107 | <View style={{ flex: 1, flexDirection: 'row', flexGrow: 0, paddingVertical: 10 }}>
|
| 108 | <Ionicons name="moon-outline" size={20} color="#64748B" />
|
| 109 |
|
| 110 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 111 | Sono
|
| 112 | </Text>
|
| 113 | </View>
|
| 114 |
|
| 115 | <Text style={{ ...Typography.headlineMd, marginBottom: 10 }}>
|
| 116 | 7h 30m
|
| 117 | </Text>
|
| 118 |
|
| 119 | <Text style={styles.indicatorGreen}>
|
| 120 | +45min que ontem
|
| 121 | </Text>
|
| 122 | </Card>
|
| 123 | </Grid>
|
| 124 | </Section>
|
| 125 |
|
| 126 | <Section>
|
| 127 | <SectionHeader title="Registros recentes" />
|
| 128 |
|
| 129 | {isLoading ? (
|
| 130 | <ActivityIndicator />
|
| 131 | ) : (
|
| 132 | <Col gap={8}>
|
| 133 | {recentEntries.map((entry) => (
|
| 134 | <MoodEntryLog key={entry.id} entry={entry} />
|
| 135 | ))}
|
| 136 | </Col>
|
| 137 | )}
|
| 138 | </Section>
|
| 139 | </ScreenLayout>
|
| 140 | )
|
| 141 | }
|
| 142 |
|
| 143 | const styles = StyleSheet.create({
|
| 144 | quickRegisterHeader: {
|
| 145 | marginTop: 16,
|
| 146 | paddingLeft: 16,
|
| 147 | paddingRight: 16
|
| 148 | },
|
| 149 | quickRegisterTitle: {
|
| 150 | ...Typography.bodyLg
|
| 151 | },
|
| 152 | // TODO: Replace when we have badges
|
| 153 | quickRegisterBadge: {
|
| 154 | fontSize: 12,
|
| 155 | lineHeight: 16
|
| 156 | },
|
| 157 | quickRegisterButton: {
|
| 158 | marginLeft: 16,
|
| 159 | marginRight: 16,
|
| 160 | marginBottom: 16,
|
| 161 | ...Shadows.lg
|
| 162 | },
|
| 163 | lineTrack: {
|
| 164 | height: 6,
|
| 165 | backgroundColor: Colors.light.divider,
|
| 166 | borderRadius: BorderRadius.full,
|
| 167 | marginBottom: 4,
|
| 168 | overflow: 'hidden',
|
| 169 | },
|
| 170 | lineFill: {
|
| 171 | height: '100%',
|
| 172 | backgroundColor: Colors.light.tint,
|
| 173 | borderRadius: BorderRadius.full,
|
| 174 | },
|
| 175 | indicatorGreen: {
|
| 176 | color: Colors.light.tint,
|
| 177 | fontSize: 11,
|
| 178 | fontWeight: 600,
|
| 179 | lineHeight: 16.5
|
| 180 | }
|
| 181 | });
|