From 472e5609e344568f1497c99e69814e33acd0efa1 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Tue, 3 Mar 2026 12:12:43 -0500 Subject: [PATCH] Add remove/clear buttons for search history in command palette Co-Authored-By: Claude Opus 4.6 --- components/command-palette.tsx | 53 ++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/components/command-palette.tsx b/components/command-palette.tsx index d753c32..7249611 100644 --- a/components/command-palette.tsx +++ b/components/command-palette.tsx @@ -6,6 +6,7 @@ import { IconKeyboard, IconMovie, IconSearch, + IconX, } from "@tabler/icons-react"; import { useHotkey, useHotkeySequence } from "@tanstack/react-hotkeys"; import { useAtom } from "jotai"; @@ -65,6 +66,15 @@ function addRecentSearch(query: string) { localStorage.setItem(RECENT_KEY, JSON.stringify(recent.slice(0, MAX_RECENT))); } +function removeRecentSearch(query: string) { + const recent = getRecentSearches().filter((q) => q !== query); + localStorage.setItem(RECENT_KEY, JSON.stringify(recent)); +} + +function clearRecentSearches() { + localStorage.removeItem(RECENT_KEY); +} + export function CommandPalette() { const router = useRouter(); const [commandPaletteOpen, setCommandPaletteOpen] = useAtom( @@ -135,6 +145,16 @@ export function CommandPalette() { setQuery(q); }, []); + const handleRemoveRecent = useCallback((q: string) => { + removeRecentSearch(q); + setRecentSearches((prev) => prev.filter((s) => s !== q)); + }, []); + + const handleClearRecent = useCallback(() => { + clearRecentSearches(); + setRecentSearches([]); + }, []); + const hasQuery = query.trim().length > 0; // Group shortcuts by scope for help dialog @@ -233,17 +253,46 @@ export function CommandPalette() { {!hasQuery && ( <> {recentSearches.length > 0 && ( - + + Recent Searches + + + } + > {recentSearches.map((q) => ( handleRecentSearch(q)} + className="group" > - {q} + {q} + + + ))}