import { useCallback, useEffect, useRef, useState } from "react"; import { View, Text, FlatList, Pressable, ActivityIndicator, } from "react-native"; import { router, useFocusEffect } from "expo-router"; import { getIncidents } from "@/lib/db"; import { useSettings } from "@/hooks/useSettings"; import type { Incident } from "@/types/incident"; import { Colors } from "@/constants/theme"; export default function HomeScreen() { const [incidents, setIncidents] = useState([]); const [loading, setLoading] = useState(true); const { settings, ready } = useSettings(); const didRedirect = useRef(false); useEffect(() => { if (!ready || didRedirect.current) return; if (settings.homeView === "capture") { didRedirect.current = true; router.push("/new"); } }, [ready, settings.homeView]); useFocusEffect( useCallback(() => { loadIncidents(); }, []) ); async function loadIncidents() { setLoading(true); const data = await getIncidents(10); setIncidents(data); setLoading(false); } return ( {loading ? ( ) : ( item.id} contentContainerStyle={{ padding: 16, paddingBottom: 96 }} ListEmptyComponent={ No incidents. Press + to log one. } renderItem={({ item }) => ( router.push(`/incident/${item.id}`)} style={{ backgroundColor: Colors.surface, borderRadius: 8, padding: 16, marginBottom: 10, borderLeftWidth: 3, borderLeftColor: item.status === "open" ? Colors.warning : Colors.success, }} > {item.title || "Untitled"} {item.status} {item.service || "—"} · {item.createdAt.slice(0, 10)} )} /> )} {/* FAB */} router.push("/new")} style={{ position: "absolute", bottom: 24, right: 24, width: 56, height: 56, borderRadius: 28, backgroundColor: Colors.primary, alignItems: "center", justifyContent: "center", elevation: 6, }} > + ); }