ui: filter deletedAt in History en Dashboard, soft delete in History

This commit is contained in:
eddy 2026-07-20 17:01:39 +02:00
commit 8e1783306a
2 changed files with 14 additions and 9 deletions

View file

@ -19,9 +19,9 @@ export default function DashboardScreen({ navigation }: Props) {
const load = async () => { const load = async () => {
await initDatabase() await initDatabase()
const allM = await getAllMeasurements() const allM = await getAllMeasurements()
setAll(allM) const visible = allM.filter(m => !m.deletedAt)
const latestM = await getLatestMeasurement() setAll(visible)
setLatest(latestM) setLatest(visible.length > 0 ? visible[0] : null)
} }
load() load()
}, []) }, [])

View file

@ -1,8 +1,10 @@
import React, { useCallback, useState } from 'react' import React, { useCallback, useState } from 'react'
import { View, FlatList, StyleSheet, Text, RefreshControl, TouchableOpacity } from 'react-native' import { View, FlatList, StyleSheet, Text, RefreshControl, TouchableOpacity, Alert } from 'react-native'
import { useFocusEffect } from '@react-navigation/native' import { useFocusEffect } from '@react-navigation/native'
import { initDatabase, getAllMeasurements, deleteMeasurement } from '../database/db' import { initDatabase, getAllMeasurements, setDeletedAt, removeMeasurement } from '../database/db'
import { Measurement } from '../types' import { Measurement } from '../types'
import { createApi } from '../sync/api'
import { getApiConfig } from './SettingsScreen'
import MeasurementRow from '../components/MeasurementRow' import MeasurementRow from '../components/MeasurementRow'
type Props = { navigation: any } type Props = { navigation: any }
@ -14,7 +16,7 @@ export default function HistoryScreen({ navigation }: Props) {
const load = useCallback(async () => { const load = useCallback(async () => {
await initDatabase() await initDatabase()
const all = await getAllMeasurements() const all = await getAllMeasurements()
setMeasurements(all) setMeasurements(all.filter(m => !m.deletedAt))
}, []) }, [])
useFocusEffect( useFocusEffect(
@ -61,10 +63,13 @@ export default function HistoryScreen({ navigation }: Props) {
style: 'destructive', style: 'destructive',
onPress: async () => { onPress: async () => {
await initDatabase() await initDatabase()
await deleteMeasurement(m.id) await setDeletedAt(m.id)
try { try {
const { syncAll } = await import('../sync/syncService') const config = await getApiConfig()
await syncAll() if (config) {
await createApi(config).deleteMeasurement(m.id)
await removeMeasurement(m.id)
}
} catch {} } catch {}
load() load()
}, },