Fix bugs from code review (state flow, idle timer, logger, kiosk, temp files)

This commit is contained in:
2026-05-31 20:10:23 +02:00
parent 58015340a2
commit a922ec29c4
5 changed files with 133 additions and 66 deletions
+44 -8
View File
@@ -1,11 +1,12 @@
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, SafeAreaView, StatusBar } from 'react-native';
import { StyleSheet, View, SafeAreaView, StatusBar, ActivityIndicator } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import CameraScreen from './src/screens/CameraScreen';
import PreviewScreen from './src/screens/PreviewScreen';
import AdminScreen from './src/screens/AdminScreen';
import { loadSettings, saveSettings, AppSettings } from './src/services/settings';
import { logger } from './src/services/logger';
import * as FileSystem from 'expo-file-system/legacy';
// Set up global error handler
const defaultErrorHandler = (global as any).ErrorUtils.getGlobalHandler();
@@ -24,6 +25,7 @@ type ScreenState = 'home' | 'camera' | 'preview' | 'admin';
export default function App() {
const [currentScreen, setCurrentScreen] = useState<ScreenState>('home');
const [photoUris, setPhotoUris] = useState<string[]>([]);
const [captureHistory, setCaptureHistory] = useState<number[]>([]);
const [settings, setSettings] = useState<AppSettings | null>(null);
// 1. Load configuration settings on app start
@@ -45,19 +47,29 @@ export default function App() {
}, []);
if (!settings) {
return <View style={styles.loadingContainer} />;
return (
<View style={styles.loadingContainer}>
<StatusBar hidden={true} />
<ActivityIndicator size="large" color="#ff2bd6" />
</View>
);
}
// 2. Navigation Actions
const handleStartBooth = () => {
setPhotoUris([]);
setCaptureHistory([]);
setCurrentScreen('camera');
};
const handlePhotoCaptured = async (uri: string) => {
await logger.log(`Photo captured via CameraScreen: ${uri}`);
try {
setPhotoUris((prev) => [...prev, uri]);
setPhotoUris((prev) => {
const next = [...prev, uri];
return next.length > 4 ? next.slice(-4) : next;
});
setCaptureHistory((prev) => [...prev, 1]);
setCurrentScreen('preview');
await logger.log('State updated to preview screen successfully.');
} catch (e) {
@@ -67,15 +79,30 @@ export default function App() {
// Called by CameraScreen when burst mode completes all photos
const handleBurstComplete = (uris: string[]) => {
setPhotoUris((prev) => [...prev, ...uris]);
setPhotoUris((prev) => {
const next = [...prev, ...uris];
return next.length > 4 ? next.slice(-4) : next;
});
setCaptureHistory((prev) => [...prev, uris.length]);
setCurrentScreen('preview');
};
const handleRetakeLast = () => {
// Remove last captured photo
const handleRetakeLast = async () => {
// Remove photos from the last capture event
const lastCaptureCount = captureHistory.length > 0 ? captureHistory[captureHistory.length - 1] : 1;
const updatedUris = [...photoUris];
updatedUris.pop();
const removedUris = updatedUris.splice(-lastCaptureCount, lastCaptureCount);
setPhotoUris(updatedUris);
setCaptureHistory((prev) => prev.slice(0, -1));
// Clean up temp files
for (const uri of removedUris) {
try {
await FileSystem.deleteAsync(uri, { idempotent: true });
} catch (e) {
console.warn('Failed to delete temp file:', e);
}
}
// Always let user retake
setCurrentScreen('camera');
@@ -85,8 +112,17 @@ export default function App() {
setCurrentScreen('camera');
};
const handleReset = () => {
const handleReset = async () => {
// Clean up temp files
for (const uri of photoUris) {
try {
await FileSystem.deleteAsync(uri, { idempotent: true });
} catch (e) {
console.warn('Failed to delete temp file:', e);
}
}
setPhotoUris([]);
setCaptureHistory([]);
setCurrentScreen('home'); // Go to home when cancelled
};