Add loading indicator to home screen while agents are fetching

useAggregatedAgents now returns { groups, isLoading } where isLoading is true
while the daemon registry loads or while hosts are connecting without a session.
HomeScreen shows an ActivityIndicator during loading, then either the agent
list or empty state. Offline hosts don't block loading—only connecting hosts do.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-11-26 20:07:33 +01:00
co-authored by Claude
parent 69881d3862
commit 0c571f6f43
3 changed files with 79 additions and 14 deletions
@@ -9,6 +9,11 @@ export interface AggregatedAgentGroup {
agents: Agent[];
}
export interface AggregatedAgentsResult {
groups: AggregatedAgentGroup[];
isLoading: boolean;
}
const sortAgents = (agents: Agent[]): Agent[] => {
return [...agents].sort((left, right) => {
const leftRunning = left.status === "running";
@@ -25,8 +30,8 @@ const sortAgents = (agents: Agent[]): Agent[] => {
});
};
export function useAggregatedAgents(): AggregatedAgentGroup[] {
const { connectionStates } = useDaemonConnections();
export function useAggregatedAgents(): AggregatedAgentsResult {
const { connectionStates, isLoading: registryLoading } = useDaemonConnections();
const sessionDirectory = useSessionDirectory();
return useMemo(() => {
@@ -76,6 +81,19 @@ export function useAggregatedAgents(): AggregatedAgentGroup[] {
return left.serverLabel.localeCompare(right.serverLabel);
});
return aggregatedGroups;
}, [sessionDirectory, connectionStates]);
// Loading if registry is still loading, or if any host is connecting and hasn't
// reported agents yet (idle hosts that haven't connected don't block loading)
let isLoading = registryLoading;
if (!isLoading && connectionStates.size > 0) {
for (const [serverId, record] of connectionStates) {
const hasSession = sessionDirectory.has(serverId);
if (record.status === "connecting" && !hasSession) {
isLoading = true;
break;
}
}
}
return { groups: aggregatedGroups, isLoading };
}, [sessionDirectory, connectionStates, registryLoading]);
}