From cda6299e8d25d9138df95e9b89b96445fe3b76ef Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sat, 18 Jan 2025 14:34:25 -0800 Subject: [PATCH] remove loading --- gui/src/context/SubmenuContextProviders.tsx | 172 ++++++++++---------- 1 file changed, 84 insertions(+), 88 deletions(-) diff --git a/gui/src/context/SubmenuContextProviders.tsx b/gui/src/context/SubmenuContextProviders.tsx index 0abaec124..c2164d70a 100644 --- a/gui/src/context/SubmenuContextProviders.tsx +++ b/gui/src/context/SubmenuContextProviders.tsx @@ -217,95 +217,91 @@ export const SubmenuContextProvidersProvider = ({ ); const loadSubmenuItems = useCallback( - async (providers: "dependsOnIndexing" | "all" | ContextProviderName[]) => { - await Promise.allSettled( - submenuContextProviders.map( - async (description: ContextProviderDescription) => { - try { - if (providersLoading.has(description.title)) { - return; - } - providersLoading.add(description.title); - - const refreshProvider = - providers === "all" - ? true - : providers === "dependsOnIndexing" - ? description.dependsOnIndexing - : providers.includes(description.title); - - if (!refreshProvider) { - return; - } - - if (description.dependsOnIndexing && disableIndexing) { - console.debug( - `Skipping ${description.title} provider due to disabled indexing`, - ); - return; - } - const result = await ideMessenger.request( - "context/loadSubmenuItems", - { - title: description.title, - }, - ); - - if (result.status === "error") { - throw new Error(result.error); - } - const submenuItems = result.content; - const providerTitle = description.title; - - const itemsWithProvider = submenuItems.map((item) => ({ - ...item, - providerTitle, - })); - - const minisearch = new MiniSearch( - { - fields: ["title", "description"], - storeFields: ["id", "title", "description", "providerTitle"], - }, - ); - - minisearch.addAll( - submenuItems.map((item) => ({ ...item, providerTitle })), - ); - - setMinisearches((prev) => ({ - ...prev, - [providerTitle]: minisearch, - })); - - if (providerTitle === "file") { - setFallbackResults((prev) => ({ - ...prev, - file: deduplicateArray( - [...lastOpenFilesRef.current, ...(prev.file ?? [])], - (a, b) => a.id === b.id, - ), - })); - } else { - setFallbackResults((prev) => ({ - ...prev, - [providerTitle]: itemsWithProvider, - })); - } - } catch (error) { - console.error( - `Error loading items for ${description.title}:`, - error, - ); - console.error( - "Error details:", - JSON.stringify(error, Object.getOwnPropertyNames(error)), - ); - } finally { - providersLoading.delete(description.title); + (providers: "dependsOnIndexing" | "all" | ContextProviderName[]) => { + submenuContextProviders.forEach( + async (description: ContextProviderDescription) => { + try { + if (providersLoading.has(description.title)) { + return; } - }, - ), + providersLoading.add(description.title); + + const refreshProvider = + providers === "all" + ? true + : providers === "dependsOnIndexing" + ? description.dependsOnIndexing + : providers.includes(description.title); + + if (!refreshProvider) { + return; + } + + if (description.dependsOnIndexing && disableIndexing) { + console.debug( + `Skipping ${description.title} provider due to disabled indexing`, + ); + return; + } + const result = await ideMessenger.request( + "context/loadSubmenuItems", + { + title: description.title, + }, + ); + + if (result.status === "error") { + throw new Error(result.error); + } + const submenuItems = result.content; + const providerTitle = description.title; + + const itemsWithProvider = submenuItems.map((item) => ({ + ...item, + providerTitle, + })); + + const minisearch = new MiniSearch({ + fields: ["title", "description"], + storeFields: ["id", "title", "description", "providerTitle"], + }); + + minisearch.addAll( + submenuItems.map((item) => ({ ...item, providerTitle })), + ); + + setMinisearches((prev) => ({ + ...prev, + [providerTitle]: minisearch, + })); + + if (providerTitle === "file") { + setFallbackResults((prev) => ({ + ...prev, + file: deduplicateArray( + [...lastOpenFilesRef.current, ...(prev.file ?? [])], + (a, b) => a.id === b.id, + ), + })); + } else { + setFallbackResults((prev) => ({ + ...prev, + [providerTitle]: itemsWithProvider, + })); + } + } catch (error) { + console.error( + `Error loading items for ${description.title}:`, + error, + ); + console.error( + "Error details:", + JSON.stringify(error, Object.getOwnPropertyNames(error)), + ); + } finally { + providersLoading.delete(description.title); + } + }, ); }, [submenuContextProviders, disableIndexing, providersLoading],