-
Notifications
You must be signed in to change notification settings - Fork 0
feat(phase6): native responder app — Capacitor, telemetry, field workflows, roster ops #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
0f461bf
e061bf4
df155c1
ef8467a
23ff79f
346aaab
a2c5254
7ba4e00
be61329
30bd1aa
0e82790
eaf0924
a890a4d
181cf62
7ba5d47
f76be20
ec6424c
f8461af
54846d5
fa98982
7f74e7f
d607b19
0c95fcb
5853522
b2f70f9
7913469
07591ab
736ab8a
5e909d5
6b02486
9a1b93c
9a9ffdb
23ca286
6906024
63787f3
e3b6ea1
d800155
e709118
5b92722
70350d9
62dae79
011b39f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,3 +57,5 @@ Thumbs.db | |
| # Worktrees | ||
| .worktrees/ | ||
| worktrees/ | ||
| !apps/responder-app/ios/ | ||
| !apps/responder-app/android/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { useEffect, useState } from 'react' | ||
| import { collection, onSnapshot, query, where } from 'firebase/firestore' | ||
| import { db } from '../app/firebase' | ||
|
|
||
| export interface AgencyAssistanceRequest { | ||
| id: string | ||
| reportId: string | ||
| requestedByMunicipality: string | ||
| message: string | ||
| priority: 'urgent' | 'normal' | ||
| status: 'pending' | 'accepted' | 'declined' | 'fulfilled' | 'expired' | ||
| targetAgencyId: string | ||
| createdAt: number | ||
| } | ||
|
|
||
| export interface BackupRequest { | ||
| id: string | ||
| reportId: string | ||
| municipalityId: string | ||
| reason: string | ||
| status: 'pending' | 'accepted' | 'declined' | 'fulfilled' | 'expired' | ||
| agencyId: string | ||
| createdAt: number | ||
| } | ||
|
|
||
| export function useAgencyAssistanceQueue(agencyId: string | undefined) { | ||
| const [requests, setRequests] = useState<AgencyAssistanceRequest[]>([]) | ||
| const [backupRequests, setBackupRequests] = useState<BackupRequest[]>([]) | ||
| const [loading, setLoading] = useState(true) | ||
| const [error, setError] = useState<string | null>(null) | ||
|
|
||
| useEffect(() => { | ||
| queueMicrotask(() => { | ||
| setError(null) | ||
| }) | ||
|
|
||
| if (!agencyId) { | ||
| queueMicrotask(() => { | ||
| setLoading(false) | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| queueMicrotask(() => { | ||
| setLoading(true) | ||
| }) | ||
|
Comment on lines
+68
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial State reset via queueMicrotask has subtle timing. The Consider synchronous state reset for clarity: ♻️ Simpler synchronous reset useEffect(() => {
- queueMicrotask(() => {
- setError(null)
- setRequests([])
- setBackupRequests([])
- })
+ setError(null)
+ setRequests([])
+ setBackupRequests([])
if (!agencyId) {
- queueMicrotask(() => {
- setLoading(false)
- })
+ setLoading(false)
return
}
- queueMicrotask(() => {
- setLoading(true)
- })
+ setLoading(true)🤖 Prompt for AI Agents |
||
|
|
||
| const q = query( | ||
| collection(db, 'agency_assistance_requests'), | ||
| where('targetAgencyId', '==', agencyId), | ||
| ) | ||
|
|
||
| const unsubscribe = onSnapshot( | ||
| q, | ||
| (snapshot) => { | ||
| const docs: AgencyAssistanceRequest[] = snapshot.docs.map((doc) => ({ | ||
| id: doc.id, | ||
| ...doc.data(), | ||
| })) as AgencyAssistanceRequest[] | ||
| setRequests(docs) | ||
| setLoading(false) | ||
| }, | ||
| (err) => { | ||
| setError(err.message) | ||
| setLoading(false) | ||
| }, | ||
| ) | ||
|
|
||
| const backupQ = query(collection(db, 'backup_requests'), where('agencyId', '==', agencyId)) | ||
|
|
||
| const unsubscribeBackup = onSnapshot( | ||
| backupQ, | ||
| (snapshot) => { | ||
| const docs: BackupRequest[] = snapshot.docs.map((doc) => ({ | ||
| id: doc.id, | ||
| ...doc.data(), | ||
| })) as BackupRequest[] | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| setBackupRequests(docs) | ||
| }, | ||
| () => { | ||
| // Backup request errors are non-fatal; don't overwrite main error state | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| return () => { | ||
| unsubscribe() | ||
| unsubscribeBackup() | ||
| } | ||
| }, [agencyId]) | ||
|
|
||
| return { requests, backupRequests, loading, error } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { useEffect, useState } from 'react' | ||
| import { collection, onSnapshot, query, where } from 'firebase/firestore' | ||
| import { db } from '../app/firebase' | ||
| import { callables } from '../services/callables' | ||
|
|
||
| export interface RosterResponder { | ||
| uid: string | ||
| displayName: string | ||
| availabilityStatus: string | ||
| lastTelemetryAt: number | null | ||
| municipalityId: string | ||
| } | ||
|
|
||
| export function useRosterManagement(agencyId: string | undefined) { | ||
| const [responders, setResponders] = useState<RosterResponder[]>([]) | ||
| const [loading, setLoading] = useState(true) | ||
| const [error, setError] = useState<string | null>(null) | ||
|
|
||
| useEffect(() => { | ||
| queueMicrotask(() => { | ||
| setResponders([]) | ||
| setError(null) | ||
| }) | ||
|
|
||
| if (!agencyId) { | ||
| queueMicrotask(() => { | ||
| setLoading(false) | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| queueMicrotask(() => { | ||
| setLoading(true) | ||
| }) | ||
|
|
||
| const q = query(collection(db, 'responders'), where('agencyId', '==', agencyId)) | ||
|
|
||
| const unsubscribe = onSnapshot( | ||
| q, | ||
| (snapshot) => { | ||
| const docs: RosterResponder[] = snapshot.docs.map((d) => { | ||
| const data = d.data() | ||
| return { | ||
| uid: d.id, | ||
| displayName: String(data.displayName ?? d.id), | ||
| availabilityStatus: String(data.availabilityStatus ?? 'unknown'), | ||
| lastTelemetryAt: typeof data.lastTelemetryAt === 'number' ? data.lastTelemetryAt : null, | ||
| municipalityId: String(data.municipalityId ?? ''), | ||
| } | ||
| }) | ||
| setResponders(docs) | ||
| setLoading(false) | ||
| }, | ||
| (err) => { | ||
| setError(err.message) | ||
| setLoading(false) | ||
| }, | ||
| ) | ||
|
|
||
| return () => { | ||
| unsubscribe() | ||
| } | ||
| }, [agencyId]) | ||
|
|
||
| const suspendResponder = async (uid: string) => { | ||
| await callables.suspendResponder({ uid, idempotencyKey: crypto.randomUUID() }) | ||
| } | ||
|
|
||
| const revokeResponder = async (uid: string) => { | ||
| await callables.revokeResponder({ uid, idempotencyKey: crypto.randomUUID() }) | ||
| } | ||
|
|
||
| const bulkAvailabilityOverride = async (uids: string[], status: string) => { | ||
| await callables.bulkAvailabilityOverride({ | ||
| uids, | ||
| status, | ||
| idempotencyKey: crypto.randomUUID(), | ||
| }) | ||
| } | ||
|
|
||
| return { responders, loading, error, suspendResponder, revokeResponder, bulkAvailabilityOverride } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the previous queue state when the agency context changes.
If
agencyIdbecomesundefinedor switches from one agency to another, this hook keeps returning the old agency'srequests/backupRequestsuntil another snapshot arrives. That leaks stale cross-agency data into the UI during logout or tenant switches.♻️ Proposed fix
if (!agencyId) { - queueMicrotask(() => { - setLoading(false) - }) + setRequests([]) + setBackupRequests([]) + setLoading(false) return } - queueMicrotask(() => { - setLoading(true) - }) + setRequests([]) + setBackupRequests([]) + setLoading(true)📝 Committable suggestion
🤖 Prompt for AI Agents