Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/tui/src/components/PromptsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function PromptsTab({
const { selectedIndex, firstVisible, setSelection } = useSelectableList(
prompts.length,
visibleCount,
{ resetWhen: [prompts] },
{ resetWhen: prompts },
);
const [error, setError] = useState<string | null>(null);
const scrollViewRef = useRef<ScrollViewRef>(null);
Expand Down
2 changes: 1 addition & 1 deletion clients/tui/src/components/ResourcesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function ResourcesTab({
const { selectedIndex, firstVisible, setSelection } = useSelectableList(
totalCount,
visibleCount,
{ resetWhen: [resources] },
{ resetWhen: resources },
);
const selectedItem = useMemo(
() => allItems[selectedIndex] || null,
Expand Down
2 changes: 1 addition & 1 deletion clients/tui/src/components/ToolsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ToolsTab({
const { selectedIndex, firstVisible, setSelection } = useSelectableList(
tools.length,
visibleCount,
{ resetWhen: [tools] },
{ resetWhen: tools },
);
const [error] = useState<string | null>(null);
const scrollViewRef = useRef<ScrollViewRef>(null);
Expand Down
8 changes: 4 additions & 4 deletions clients/tui/src/hooks/useSelectableList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function clampFirstVisible(
}

export interface UseSelectableListOptions {
/** When these change, reset selection to 0 (e.g. [tools] when switching servers) */
resetWhen?: unknown[];
/** When this reference changes, reset selection to 0 (e.g. tools list when switching servers) */
resetWhen?: unknown;
}

/**
Expand All @@ -38,9 +38,9 @@ export function useSelectableList(
[visibleCount],
);

// Reset when deps change (e.g. different server)
// Reset when the list reference changes (e.g. different server).
useEffect(() => {
if (options?.resetWhen) {
if (options?.resetWhen !== undefined) {
setSelectedIndex(0);
setFirstVisible(0);
}
Expand Down