| 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 } from '@/constants/theme';
|
| 20 | import { router } from 'expo-router';
|
| 21 | import {
|
| 22 | MoodDefinition, MOODS
|
| 23 | } from '@/constants/moods'
|
| 24 |
|
| 25 | import {
|
| 26 | useThemeColor,
|
| 27 | useMoodEntries
|
| 28 | } from '@/hooks';
|
| 29 |
|
| 30 | import MoodEntryLog from '@/components/ui/MoodEntryLog';
|
| 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 userName={user.firstName} userAvatar={user.avatarURL}
|
| 47 | onNotificationPress={() => console.log('Notifications')}
|
| 48 | showNotificationBadge={true}>
|
| 49 | <Section>
|
| 50 | <SectionHeader
|
| 51 | title="Como você está hoje?"
|
| 52 | subtitle="Sua jornada começa agora"
|
| 53 | >
|
| 54 | </SectionHeader>
|
| 55 |
|
| 56 | <Card style={{ minHeight: 200 }}>
|
| 57 | <Col gap={16}>
|
| 58 | <Between style={styles.quickRegisterHeader}>
|
| 59 | <ThemedText style={styles.quickRegisterTitle}>
|
| 60 | Registro rápido
|
| 61 | </ThemedText>
|
| 62 |
|
| 63 | <ThemedText style={styles.quickRegisterBadge}>
|
| 64 | HOJE
|
| 65 | </ThemedText>
|
| 66 | </Between>
|
| 67 |
|
| 68 | <MoodSelector
|
| 69 | style={{paddingLeft: 8, paddingRight: 8, paddingTop: 16 }}
|
| 70 | items={MOODS}
|
| 71 | value={mood}
|
| 72 | onSelect={setMood}
|
| 73 | />
|
| 74 |
|
| 75 | <Button
|
| 76 | title="Salvar Humor"
|
| 77 | onPress={initQuickRegister}
|
| 78 | style={styles.quickRegisterButton}
|
| 79 | />
|
| 80 | </Col>
|
| 81 | </Card>
|
| 82 | </Section>
|
| 83 |
|
| 84 | {/* TODO: Check whether we gonna have to generate these on demand */}
|
| 85 | <Section>
|
| 86 | <Grid gap={4}>
|
| 87 | <Card style={{minHeight: 150, backgroundColor: 'powderblue'}}>
|
| 88 | </Card>
|
| 89 |
|
| 90 | <Card style={{minHeight: 150, backgroundColor: 'tomato'}}>
|
| 91 | </Card>
|
| 92 | </Grid>
|
| 93 | </Section>
|
| 94 |
|
| 95 | <Section>
|
| 96 | <SectionHeader title="Registros recentes" />
|
| 97 |
|
| 98 | {isLoading ? (
|
| 99 | <ActivityIndicator />
|
| 100 | ) : (
|
| 101 | <Col gap={8}>
|
| 102 | {recentEntries.map((entry) => (
|
| 103 | <MoodEntryLog key={entry.id} entry={entry} />
|
| 104 | ))}
|
| 105 | </Col>
|
| 106 | )}
|
| 107 | </Section>
|
| 108 | </ScreenLayout>
|
| 109 | )
|
| 110 | }
|
| 111 |
|
| 112 | const styles = StyleSheet.create({
|
| 113 | quickRegisterHeader: {
|
| 114 | marginTop: 16,
|
| 115 | paddingLeft: 16,
|
| 116 | paddingRight: 16
|
| 117 | },
|
| 118 | quickRegisterTitle: {
|
| 119 | ...Typography.bodyLg
|
| 120 | },
|
| 121 | // TODO: Replace when we have badges
|
| 122 | quickRegisterBadge: {
|
| 123 | fontSize: 12,
|
| 124 | lineHeight: 16
|
| 125 | },
|
| 126 | quickRegisterButton: {
|
| 127 | marginLeft: 16,
|
| 128 | marginRight: 16,
|
| 129 | marginBottom: 16,
|
| 130 | ...Shadows.lg
|
| 131 | }
|
| 132 | });
|