big ui and intel updates

This commit is contained in:
Logan
2026-04-19 16:48:55 -04:00
parent 0df53df92e
commit 303c5b13cf
11 changed files with 527 additions and 169 deletions
+33
View File
@@ -48,6 +48,39 @@ export function useCalls(limitCount = 50) {
return { calls, loading, error };
}
export function useCallsByIncident(incidentId: string | null) {
const [calls, setCalls] = useState<CallRecord[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!incidentId) { setLoading(false); return; }
let unsubFirestore: (() => void) | undefined;
const unsubAuth = onAuthStateChanged(auth, (user) => {
if (unsubFirestore) { unsubFirestore(); unsubFirestore = undefined; }
if (!user) { setLoading(false); return; }
const toISO = (v: any): string | null =>
v?.toDate?.()?.toISOString?.() ?? (typeof v === "string" ? v : null);
const q = query(collection(db, "calls"), where("incident_id", "==", incidentId));
unsubFirestore = onSnapshot(q, (snap) => {
const docs = snap.docs.map((d) => {
const data = d.data();
return { ...data, started_at: toISO(data.started_at) ?? "", ended_at: toISO(data.ended_at) } as CallRecord;
});
docs.sort((a, b) => a.started_at.localeCompare(b.started_at));
setCalls(docs);
setLoading(false);
}, (err: FirestoreError) => { console.error("useCallsByIncident:", err); setLoading(false); });
});
return () => { unsubAuth(); if (unsubFirestore) unsubFirestore(); };
}, [incidentId]);
return { calls, loading };
}
export function useActiveCalls() {
const [calls, setCalls] = useState<CallRecord[]>([]);