marmar-context / web / context / src / clinician / checkin / confirmations.ts
confirmations.ts
Raw
// YCI-1a: "I will speak to Mariam today", held in memory for this tab only (PAT-5).
import { useSyncExternalStore } from "react";
import type { CallConfirmation } from "../../logic/urgent";

const confirmations = new Map<string, CallConfirmation>();
const listeners = new Set<() => void>();

export function confirmCall(patientId: string) {
  confirmations.set(patientId, { patientId, confirmedAt: new Date().toISOString() });
  listeners.forEach((l) => l());
}

export function useCallConfirmation(patientId: string): CallConfirmation | null {
  return useSyncExternalStore(
    (l) => {
      listeners.add(l);
      return () => listeners.delete(l);
    },
    () => confirmations.get(patientId) ?? null,
  );
}