ui: voeg laad-indicator toe aan Dashboard
This commit is contained in:
parent
e93d12565e
commit
df91f4d46f
1 changed files with 12 additions and 2 deletions
|
|
@ -13,15 +13,18 @@ export default function DashboardScreen({ navigation }: Props) {
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const [latest, setLatest] = useState<Measurement | null>(null)
|
const [latest, setLatest] = useState<Measurement | null>(null)
|
||||||
const [all, setAll] = useState<Measurement[]>([])
|
const [all, setAll] = useState<Measurement[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
|
setLoading(true)
|
||||||
await initDatabase()
|
await initDatabase()
|
||||||
const allM = await getAllMeasurements()
|
const allM = await getAllMeasurements()
|
||||||
const visible = allM.filter(m => !m.deletedAt)
|
const visible = allM.filter(m => !m.deletedAt)
|
||||||
setAll(visible)
|
setAll(visible)
|
||||||
setLatest(visible.length > 0 ? visible[0] : null)
|
setLatest(visible.length > 0 ? visible[0] : null)
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
load()
|
load()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
@ -38,8 +41,14 @@ export default function DashboardScreen({ navigation }: Props) {
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
<ScrollView style={styles.container}>
|
<ScrollView style={styles.container}>
|
||||||
<LatestMeasurementCard measurement={latest} />
|
{loading ? (
|
||||||
<WeightChart measurements={all} />
|
<Text style={styles.loading}>Laden...</Text>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<LatestMeasurementCard measurement={latest} />
|
||||||
|
<WeightChart measurements={all} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
|
|
@ -59,4 +68,5 @@ const styles = StyleSheet.create({
|
||||||
navLink: { fontSize: 16, color: '#2196F3', fontWeight: '600' },
|
navLink: { fontSize: 16, color: '#2196F3', fontWeight: '600' },
|
||||||
fab: { backgroundColor: '#4CAF50', padding: 16, borderRadius: 8, margin: 16, alignItems: 'center' },
|
fab: { backgroundColor: '#4CAF50', padding: 16, borderRadius: 8, margin: 16, alignItems: 'center' },
|
||||||
fabText: { color: '#fff', fontSize: 16, fontWeight: '700' },
|
fabText: { color: '#fff', fontSize: 16, fontWeight: '700' },
|
||||||
|
loading: { fontSize: 16, color: '#999', textAlign: 'center', padding: 40 },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue