fix: code review cleanup — filter deletedAt, deduplicate, use toast util
- getMeasurementByDate: AND deletedAt IS NULL (soft-deleted meting triggerde dubbele-datum alert) - Dashboard/History: verwijder redundante JS .filter(m => !m.deletedAt) (SQL filterde al) - HistoryScreen confirmDelete: fix dubbele load() call - NewMeasurementScreen: gebruik toast utility i.p.v. direct ToastAndroid
This commit is contained in:
parent
df05fb75dd
commit
d09951c493
4 changed files with 12 additions and 16 deletions
|
|
@ -77,7 +77,7 @@ export async function getMeasurementsSince(date: string): Promise<Measurement[]>
|
|||
export async function getMeasurementByDate(date: string): Promise<Measurement | null> {
|
||||
const day = date.slice(0, 10)
|
||||
const rows = await db!.getAllAsync<any>(
|
||||
"SELECT * FROM measurements WHERE measuredAt LIKE ? LIMIT 1",
|
||||
"SELECT * FROM measurements WHERE measuredAt LIKE ? AND deletedAt IS NULL LIMIT 1",
|
||||
[`${day}%`]
|
||||
)
|
||||
return rows.length > 0 ? (rows[0] as Measurement) : null
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default function DashboardScreen({ navigation }: Props) {
|
|||
const load = async () => {
|
||||
// 1. Laad alleen laatste 2 metingen voor de kaart (snel!)
|
||||
await loadLatest(2)
|
||||
setAll(getCached().filter(m => !m.deletedAt))
|
||||
setAll(getCached())
|
||||
|
||||
// 2. Laad rest van de data op achtergrond voor grafieken + sync
|
||||
const loadRest = async () => {
|
||||
|
|
@ -28,7 +28,7 @@ export default function DashboardScreen({ navigation }: Props) {
|
|||
await loadSince(cutoffDate.toISOString())
|
||||
|
||||
// Update UI met grafiek-data (nog geen sync)
|
||||
setAll(getCached().filter(m => !m.deletedAt))
|
||||
setAll(getCached())
|
||||
|
||||
// Sync met server (achtergrond)
|
||||
try {
|
||||
|
|
@ -40,7 +40,7 @@ export default function DashboardScreen({ navigation }: Props) {
|
|||
}
|
||||
|
||||
// Update UI met eventuele nieuwe data van sync
|
||||
setAll(getCached().filter(m => !m.deletedAt))
|
||||
setAll(getCached())
|
||||
}
|
||||
loadRest()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default function HistoryScreen({ navigation }: Props) {
|
|||
const load = useCallback(async () => {
|
||||
await initDatabase()
|
||||
const all = await getAllMeasurements()
|
||||
setMeasurements(all.filter(m => !m.deletedAt))
|
||||
setMeasurements(all)
|
||||
}, [])
|
||||
|
||||
useFocusEffect(
|
||||
|
|
@ -72,11 +72,10 @@ export default function HistoryScreen({ navigation }: Props) {
|
|||
await createApi(config).deleteMeasurement(m.id)
|
||||
await removeMeasurement(m.id)
|
||||
}
|
||||
} catch {
|
||||
await load()
|
||||
return
|
||||
}
|
||||
load()
|
||||
} catch {
|
||||
load()
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { View, Text, Alert, Platform, ToastAndroid } from 'react-native'
|
||||
import React, { useCallback, useState } from 'react'
|
||||
import { View, Text, Alert } from 'react-native'
|
||||
import { useFocusEffect } from '@react-navigation/native'
|
||||
import MeasurementForm from '../components/MeasurementForm'
|
||||
import { Measurement } from '../types'
|
||||
import { initDatabase, insertMeasurement, upsertMeasurement, getLatestMeasurement, getMeasurementByDate } from '../database/db'
|
||||
import { updateCache } from '../store/measurementStore'
|
||||
import { showSuccess, showError } from '../utils/toast'
|
||||
|
||||
type Props = {
|
||||
navigation: any
|
||||
|
|
@ -81,13 +82,9 @@ export default function NewMeasurementScreen({ navigation, route }: Props) {
|
|||
try {
|
||||
const { uploadMeasurement } = await import('../sync/syncService')
|
||||
await uploadMeasurement(m)
|
||||
if (Platform.OS === 'android') {
|
||||
ToastAndroid.show('Opgeslagen & gesynct', ToastAndroid.SHORT)
|
||||
}
|
||||
showSuccess('Opgeslagen & gesynct')
|
||||
} catch {
|
||||
if (Platform.OS === 'android') {
|
||||
ToastAndroid.show('Opgeslagen (sync mislukt)', ToastAndroid.LONG)
|
||||
}
|
||||
showError('Opgeslagen (sync mislukt)')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue