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 () => {
await initDatabase()
const allM = await getAllMeasurements()
setAll(allM)
const latestM = await getLatestMeasurement()
setLatest(latestM)
const visible = allM.filter(m => !m.deletedAt)
setAll(visible)
setLatest(visible.length > 0 ? visible[0] : null)
}
load()
}, [])

View file

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