From 99495ff9ce29eed8deb902352be60263985dc95f Mon Sep 17 00:00:00 2001 From: simosmik Date: Thu, 30 Apr 2026 08:16:42 +0000 Subject: [PATCH] refactor(command-palette): return items array directly from source hooks --- .../command-palette/CommandPalette.tsx | 10 +++++----- .../command-palette/sources/useApiSource.ts | 20 ++----------------- .../sources/useSessionMessageSearch.ts | 2 +- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/components/command-palette/CommandPalette.tsx b/src/components/command-palette/CommandPalette.tsx index e00e2ec3..65a98943 100644 --- a/src/components/command-palette/CommandPalette.tsx +++ b/src/components/command-palette/CommandPalette.tsx @@ -95,11 +95,11 @@ export default function CommandPalette({ const showFiles = mode === 'mixed' || mode === 'files'; const showCommits = mode === 'mixed' || mode === 'commits'; - const { items: sessions } = useSessionsSource(projectId, open && showSessions); - const { items: messageMatches } = useSessionMessageSearch(projectId, query, open && showSessions); - const { items: files } = useFilesSource(projectId, open && showFiles); - const { items: commits } = useCommitsSource(projectId, open && showCommits); - const { items: branches } = useBranchesSource(projectId, open && showActions); + const sessions = useSessionsSource(projectId, open && showSessions); + const messageMatches = useSessionMessageSearch(projectId, query, open && showSessions); + const files = useFilesSource(projectId, open && showFiles); + const commits = useCommitsSource(projectId, open && showCommits); + const branches = useBranchesSource(projectId, open && showActions); const git = useGitActions(projectId); const sessionRows = React.useMemo(() => { diff --git a/src/components/command-palette/sources/useApiSource.ts b/src/components/command-palette/sources/useApiSource.ts index 73a07790..af4ae414 100644 --- a/src/components/command-palette/sources/useApiSource.ts +++ b/src/components/command-palette/sources/useApiSource.ts @@ -1,33 +1,21 @@ import { useEffect, useState } from 'react'; -export type ApiSourceState = { - items: T[]; - isLoading: boolean; - error: Error | null; -}; - export function useApiSource(opts: { enabled: boolean; deps: React.DependencyList; fetcher: (signal: AbortSignal) => Promise; parse: (raw: R) => T[]; -}): ApiSourceState { +}): T[] { const [items, setItems] = useState([]); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const { enabled, deps, fetcher, parse } = opts; useEffect(() => { if (!enabled) { setItems([]); - setError(null); return; } const controller = new AbortController(); - setIsLoading(true); - setError(null); fetcher(controller.signal) .then((r) => r.json() as Promise) @@ -39,15 +27,11 @@ export function useApiSource(opts: { if (controller.signal.aborted) return; if (err instanceof DOMException && err.name === 'AbortError') return; setItems([]); - setError(err instanceof Error ? err : new Error(String(err))); - }) - .finally(() => { - if (!controller.signal.aborted) setIsLoading(false); }); return () => controller.abort(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [enabled, ...deps]); - return { items, isLoading, error }; + return items; } diff --git a/src/components/command-palette/sources/useSessionMessageSearch.ts b/src/components/command-palette/sources/useSessionMessageSearch.ts index 87598583..7b648961 100644 --- a/src/components/command-palette/sources/useSessionMessageSearch.ts +++ b/src/components/command-palette/sources/useSessionMessageSearch.ts @@ -94,5 +94,5 @@ export function useSessionMessageSearch( }; }, []); - return { items }; + return items; }