From 0f0f9e6945039bee98120f1e512fe667070b2ac6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 4 Oct 2025 17:12:19 -0500 Subject: [PATCH] Hide recentlyUsed models in the total list --- src/components/ModelSelector.test.tsx | 18 ++++++++++++++++-- src/components/ModelSelector.tsx | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/ModelSelector.test.tsx b/src/components/ModelSelector.test.tsx index ca350262..43e97dbd 100644 --- a/src/components/ModelSelector.test.tsx +++ b/src/components/ModelSelector.test.tsx @@ -102,11 +102,17 @@ describe('ModelSelector', () => { // Wait for the dropdown to open await waitFor(() => { - expect(screen.getByText('provider1')).toBeInTheDocument(); + expect(screen.getByText('provider2')).toBeInTheDocument(); }); // Recently used section should NOT be visible expect(screen.queryByText('Recently Used')).not.toBeInTheDocument(); + + // provider1 should be hidden since all its models are in recently used + expect(screen.queryByText('provider1')).not.toBeInTheDocument(); + + // provider2 should still show with model3 + expect(screen.getByText('provider2/model3')).toBeInTheDocument(); }); it('shows recently used section when less than 5 models but some recently used are not available', async () => { @@ -198,11 +204,19 @@ describe('ModelSelector', () => { // Wait for the dropdown to open await waitFor(() => { - expect(screen.getByText('provider1')).toBeInTheDocument(); + expect(screen.getByText('provider2')).toBeInTheDocument(); }); // Recently used section SHOULD be visible expect(screen.getByText('Recently Used')).toBeInTheDocument(); + + // provider1 should be hidden since all its models are in recently used + expect(screen.queryByText('provider1')).not.toBeInTheDocument(); + + // provider2 and provider3 should still show + expect(screen.getByText('provider2/model3')).toBeInTheDocument(); + expect(screen.getByText('provider2/model4')).toBeInTheDocument(); + expect(screen.getByText('provider3/model5')).toBeInTheDocument(); }); it('hides recently used section when no recently used models exist', async () => { diff --git a/src/components/ModelSelector.tsx b/src/components/ModelSelector.tsx index 2e674c00..ad2eb95d 100644 --- a/src/components/ModelSelector.tsx +++ b/src/components/ModelSelector.tsx @@ -51,17 +51,25 @@ export function ModelSelector({ const recentlyUsedModels = useMemo(() => settings.recentlyUsedModels || [], [settings.recentlyUsedModels]); - // Group models by provider + // Create a Set of recently used model IDs for efficient lookup + const recentlyUsedSet = useMemo(() => new Set(recentlyUsedModels), [recentlyUsedModels]); + + // Group models by provider, excluding models that are in the recently used section const modelsByProvider = useMemo(() => { const groups: Record = {}; for (const model of models) { + // Skip models that are already shown in recently used + if (recentlyUsedSet.has(model.fullId)) { + continue; + } + if (!groups[model.provider]) { groups[model.provider] = []; } groups[model.provider].push(model); } return groups; - }, [models]); + }, [models, recentlyUsedSet]); // Determine if we should show the "Recently Used" section const shouldShowRecentlyUsed = useMemo(() => {