feat: add Dashboard with latest card and weight chart

This commit is contained in:
Eddy de Vink 2026-06-27 22:40:55 +02:00
commit 45b2a2c36e

View file

@ -0,0 +1,44 @@
import React, { useCallback, useState } from 'react'
import { View, ScrollView, TouchableOpacity, Text, StyleSheet } from 'react-native'
import { useFocusEffect } from '@react-navigation/native'
import { initDatabase, getAllMeasurements, getLatestMeasurement } from '../database/db'
import { Measurement } from '../types'
import LatestMeasurementCard from '../components/LatestMeasurementCard'
import WeightChart from '../components/WeightChart'
type Props = { navigation: any }
export default function DashboardScreen({ navigation }: Props) {
const [latest, setLatest] = useState<Measurement | null>(null)
const [all, setAll] = useState<Measurement[]>([])
useFocusEffect(
useCallback(() => {
const load = async () => {
await initDatabase()
const allM = await getAllMeasurements()
setAll(allM)
const latestM = await getLatestMeasurement()
setLatest(latestM)
}
load()
}, [])
)
return (
<ScrollView style={styles.container}>
<LatestMeasurementCard measurement={latest} />
<WeightChart measurements={all} />
<TouchableOpacity style={styles.fab} onPress={() => navigation.navigate('NewMeasurement')}>
<Text style={styles.fabText}>+ Nieuwe meting</Text>
</TouchableOpacity>
</ScrollView>
)
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: '#f5f5f5' },
fab: { backgroundColor: '#4CAF50', padding: 16, borderRadius: 8, margin: 16, alignItems: 'center' },
fabText: { color: '#fff', fontSize: 16, fontWeight: '700' },
})