feat: add Dashboard with latest card and weight chart
This commit is contained in:
parent
212bc700c3
commit
45b2a2c36e
1 changed files with 151 additions and 0 deletions
44
src/screens/DashboardScreen.tsx
Normal file
44
src/screens/DashboardScreen.tsx
Normal 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' },
|
||||
})
|
||||
Loading…
Reference in a new issue