detail: soft delete via deletedAt i.p.v. syncStatus
This commit is contained in:
parent
143572bc81
commit
b043a5c1d2
1 changed files with 9 additions and 4 deletions
|
|
@ -2,8 +2,10 @@ import React, { useCallback, useState } from 'react'
|
||||||
import { View, Text, StyleSheet, TouchableOpacity, Alert, ScrollView } from 'react-native'
|
import { View, Text, StyleSheet, TouchableOpacity, Alert, ScrollView } from 'react-native'
|
||||||
import { useFocusEffect } from '@react-navigation/native'
|
import { useFocusEffect } from '@react-navigation/native'
|
||||||
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
||||||
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'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: any
|
navigation: any
|
||||||
|
|
@ -57,10 +59,13 @@ export default function MeasurementDetailScreen({ navigation, route }: Props) {
|
||||||
style: 'destructive',
|
style: 'destructive',
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
await initDatabase()
|
await initDatabase()
|
||||||
await deleteMeasurement(measurementId)
|
await setDeletedAt(measurementId)
|
||||||
try {
|
try {
|
||||||
const { syncAll } = await import('../sync/syncService')
|
const config = await getApiConfig()
|
||||||
await syncAll(new Set([measurementId]))
|
if (config) {
|
||||||
|
await createApi(config).deleteMeasurement(measurementId)
|
||||||
|
await removeMeasurement(measurementId)
|
||||||
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
navigation.goBack()
|
navigation.goBack()
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue