ui: filter deletedAt in History en Dashboard, soft delete in History
This commit is contained in:
parent
b043a5c1d2
commit
8e1783306a
2 changed files with 14 additions and 9 deletions
|
|
@ -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()
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue