fix(office): persist per-floor selectedAgentId on focusLocalAgent + wire officeFloors runtime state

PR #96 findings:
- Medium #1: focusLocalAgent now writes selectedAgentId back to floorRosterCache
  so handleSelectFloor restores the agent the user last picked on each floor
  rather than snapping back to the hydration-time suggestion.
- Medium #2: Add useEffect that calls settingsCoordinator.schedulePatch with
  officeFloors[activeFloorId] patch on every status/gatewayUrl change, writing
  status, gatewayUrl, lastKnownGoodAt, lastErrorCode, and lastErrorMessage so
  the persisted floor runtime state actually tracks live connection transitions.
This commit is contained in:
gsknnft
2026-04-06 11:14:20 -04:00
parent 602c52dee8
commit 84966ed00d
+34 -1
View File
@@ -1175,8 +1175,15 @@ export function OfficeScreen({
setChatOpen(true);
}
dispatch({ type: "selectAgent", agentId });
// Keep per-floor cache in sync so handleSelectFloor can restore the last
// agent the user selected when they switch back to this floor.
setFloorRosterCache((prev) => {
const current = prev[activeFloorId];
if (!current || current.selectedAgentId === agentId) return prev;
return { ...prev, [activeFloorId]: { ...current, selectedAgentId: agentId } };
});
},
[dispatch],
[activeFloorId, dispatch],
);
const handleSelectFloor = useCallback(
(floorId: FloorId) => {
@@ -1417,6 +1424,32 @@ export function OfficeScreen({
};
}, [gatewayUrl, loadStudioSettings]);
// Wire officeFloors persisted runtime state so the status / gateway fields
// actually reflect live connection transitions (not just stay at defaults).
useEffect(() => {
const key = gatewayUrl.trim();
if (!key) return;
const patch =
status === "connected"
? {
status: "connected" as const,
gatewayUrl: key,
lastKnownGoodAt: Date.now(),
lastErrorCode: null,
lastErrorMessage: null,
}
: status === "connecting"
? { status: "connecting" as const }
: gatewayError
? {
status: "error" as const,
lastErrorCode: "GATEWAY_ERROR",
lastErrorMessage: gatewayError,
}
: { status: "disconnected" as const };
settingsCoordinator.schedulePatch({ officeFloors: { [activeFloorId]: patch } }, 0);
}, [activeFloorId, gatewayError, gatewayUrl, settingsCoordinator, status]);
const loadAgents = useCallback(async (options?: {
forceSettings?: boolean;
minIntervalMs?: number;