Use replace navigation for agent switches

This commit is contained in:
Mohamed Boudra
2026-01-01 16:55:58 +07:00
parent 0c4d1c3a58
commit b3a1729df2
3 changed files with 37 additions and 23 deletions
@@ -198,6 +198,7 @@ function AgentScreenContent({
: undefined
);
// Get parent agent ID for back navigation
const parentAgentId = agent?.parentAgentId;
+13 -4
View File
@@ -1,6 +1,6 @@
import { View, Text, Pressable, FlatList, Modal, RefreshControl, type ListRenderItem } from "react-native";
import { useCallback, useState, useMemo } from "react";
import { router } from "expo-router";
import { useCallback, useMemo, useState } from "react";
import { router, usePathname } from "expo-router";
import { StyleSheet, useUnistyles } from "react-native-unistyles";
import { formatTimeAgo } from "@/utils/time";
import { getAgentProviderDefinition } from "@server/server/agent/provider-manifest";
@@ -17,6 +17,7 @@ interface AgentListProps {
export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAgentId }: AgentListProps) {
const { theme } = useUnistyles();
const pathname = usePathname();
const [actionAgent, setActionAgent] = useState<AggregatedAgent | null>(null);
// Sort agents with requires attention at the top
@@ -56,7 +57,9 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
to: "agent",
params: { serverId, agentId },
});
router.push({
const shouldReplace = pathname.startsWith("/agent/");
const navigate = shouldReplace ? router.replace : router.push;
navigate({
pathname: "/agent/[serverId]/[agentId]",
params: {
serverId,
@@ -64,7 +67,7 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
},
});
},
[isActionSheetVisible]
[isActionSheetVisible, pathname]
);
const handleAgentLongPress = useCallback((agent: AggregatedAgent) => {
@@ -176,8 +179,14 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
contentContainerStyle={styles.listContent}
keyExtractor={keyExtractor}
renderItem={renderAgentItem}
extraData={selectedAgentId}
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="handled"
initialNumToRender={12}
windowSize={7}
maxToRenderPerBatch={12}
updateCellsBatchingPeriod={16}
removeClippedSubviews={true}
refreshControl={
onRefresh ? (
<RefreshControl
+23 -19
View File
@@ -4,6 +4,7 @@ import { useDaemonConnections } from "@/contexts/daemon-connections-context";
import { useSessionStore } from "@/stores/session-store";
import type { AgentDirectoryEntry } from "@/types/agent-directory";
import type { Agent } from "@/stores/session-store";
import { isPerfLoggingEnabled } from "@/utils/perf";
export interface AggregatedAgent extends AgentDirectoryEntry {
serverId: string;
@@ -66,7 +67,7 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
if (agent.parentAgentId) {
continue;
}
allAgents.push({
const nextAgent: AggregatedAgent = {
id: agent.id,
serverId,
serverLabel,
@@ -79,7 +80,8 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
attentionReason: agent.attentionReason,
attentionTimestamp: agent.attentionTimestamp,
parentAgentId: agent.parentAgentId,
});
};
allAgents.push(nextAgent);
}
}
@@ -138,25 +140,27 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
// isLoading: Generic loading flag (either initial or revalidating)
const isLoading = isConnecting;
const connectionStatesArray = Array.from(connectionStates.entries()).map(([id, state]) => ({
id: id.substring(0, 20) + (id.length > 20 ? '...' : ''),
status: state.status,
sessionReady: state.sessionReady,
hasEverReceivedSessionState: state.hasEverReceivedSessionState,
}));
if (isPerfLoggingEnabled()) {
const connectionStatesArray = Array.from(connectionStates.entries()).map(([id, state]) => ({
id: id.substring(0, 20) + (id.length > 20 ? '...' : ''),
status: state.status,
sessionReady: state.sessionReady,
hasEverReceivedSessionState: state.hasEverReceivedSessionState,
}));
console.log('[useAggregatedAgents] States:', {
hasAnyData,
isConnecting,
isInitialLoad,
isRevalidating,
totalConnectionStates: connectionStates.size,
connectingReasons: connectingReasons.length > 0 ? connectingReasons : 'none',
});
console.log('[useAggregatedAgents] States:', {
hasAnyData,
isConnecting,
isInitialLoad,
isRevalidating,
totalConnectionStates: connectionStates.size,
connectingReasons: connectingReasons.length > 0 ? connectingReasons : 'none',
});
console.log('[useAggregatedAgents] Connection States Detail:',
JSON.stringify(connectionStatesArray, null, 2)
);
console.log('[useAggregatedAgents] Connection States Detail:',
JSON.stringify(connectionStatesArray, null, 2)
);
}
return {
agents: allAgents,