Skip to content

Commit 7603d88

Browse files
yarin-magclaude
andcommitted
fix(demo): populate Zustand store and fake WS connected in demo mode
- Fix rules-of-hooks violation in useAgents by calling all hooks unconditionally and using enabled:false + useEffect to seed the store - filteredAgents in the grid now shows mock agents correctly - wsConnected is faked as true in demo mode (no more "Reconnecting...") Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7d88794 commit 7603d88

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

apps/web/src/features/agents/hooks/useAgents.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import { DEMO_AGENTS } from "../../../lib/demo-data";
1111

1212
export function useAgents(statusFilter?: AgentStatus) {
1313
const isDemoMode = useDemoMode();
14-
if (isDemoMode) {
15-
const agents = statusFilter ? DEMO_AGENTS.filter((a) => a.status === statusFilter) : DEMO_AGENTS;
16-
return { agents, loading: false, error: null, refetch: async () => {} };
17-
}
1814
const queryClient = useQueryClient();
1915
const setAgents = useAgentsStore((state) => state.setAgents);
2016
const updateAgent = useAgentsStore((state) => state.updateAgent);
2117

18+
// Populate the Zustand store with mock data in demo mode
19+
useEffect(() => {
20+
if (isDemoMode) setAgents(DEMO_AGENTS);
21+
}, [isDemoMode, setAgents]);
22+
2223
// Query with automatic caching and offline support
2324
const {
2425
data: agents = [],
@@ -27,6 +28,7 @@ export function useAgents(statusFilter?: AgentStatus) {
2728
refetch,
2829
} = useQuery({
2930
queryKey: [...QUERY_KEYS.agents, statusFilter],
31+
enabled: !isDemoMode,
3032
queryFn: async (): Promise<AgentSnapshot[]> => {
3133
try {
3234
// Try network first
@@ -62,6 +64,8 @@ export function useAgents(statusFilter?: AgentStatus) {
6264

6365
// WebSocket for real-time updates
6466
useEffect(() => {
67+
if (isDemoMode) return;
68+
6569
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
6670

6771
const unsubscribe = wsService.subscribe((message) => {
@@ -98,7 +102,12 @@ export function useAgents(statusFilter?: AgentStatus) {
98102
clearTimeout(debounceTimer);
99103
unsubscribe();
100104
};
101-
}, [queryClient, updateAgent]);
105+
}, [queryClient, updateAgent, isDemoMode]);
106+
107+
if (isDemoMode) {
108+
const demoAgents = statusFilter ? DEMO_AGENTS.filter((a) => a.status === statusFilter) : DEMO_AGENTS;
109+
return { agents: demoAgents, loading: false, error: null, refetch: async () => {} };
110+
}
102111

103112
return {
104113
agents,

apps/web/src/features/dashboard/hooks/useMissionControlState.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ import { useAgentsStore } from "../../agents/stores/agents.store";
66
import { apiService } from "../../../services/api.service";
77
import { QUERY_KEYS } from "../../../lib/constants";
88
import type { AgentSession } from "../../../services/calendar.service";
9+
import { useDemoMode } from "../../../hooks/useDemoMode";
910

1011
type ViewMode = "grid" | "calendar" | "table" | "kanban" | "analytics" | "compare";
1112

1213
const WS_POLL_INTERVAL_MS = 2_000;
1314

1415
export function useMissionControlState() {
16+
const isDemoMode = useDemoMode();
1517
const { agents, loading, error } = useAgents();
1618
const [clearing, setClearing] = useState(false);
1719
const [selectedSession, setSelectedSession] = useState<AgentSession | null>(null);
18-
const [wsConnected, setWsConnected] = useState(wsService.isConnected);
20+
const [wsConnected, setWsConnected] = useState(isDemoMode || wsService.isConnected);
1921

2022
useEffect(() => {
23+
if (isDemoMode) return;
2124
const interval = setInterval(() => {
2225
setWsConnected(wsService.isConnected);
2326
}, WS_POLL_INTERVAL_MS);
2427
return () => clearInterval(interval);
25-
}, []);
28+
}, [isDemoMode]);
2629

2730
const hideDisconnected = useAgentsStore((state) => state.hideDisconnected);
2831
const toggleHideDisconnected = useAgentsStore((state) => state.toggleHideDisconnected);

0 commit comments

Comments
 (0)