From b7eef3b753a917f4f426fdab9ee66355b446140b Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat Date: Mon, 9 Jun 2025 16:19:00 +0800 Subject: [PATCH] refactor: update ESLint configuration and clean up useDiscoverCategories logic - Added new path to ESLint configuration for better linting coverage. - Refactored useDiscoverCategories to simplify category handling and improve URL path matching logic. - Removed unnecessary items from initialCategories for clarity and maintainability. --- eslint.config.mjs | 3 ++- .../discover/hooks/useDiscoverCategories.ts | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 33e6ae8757..0d383eccee 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -62,7 +62,8 @@ export default defineConfig([ '.yarn/**', '.gitignore', 'scripts/cloudflare-worker.js', - 'src/main/integration/nutstore/sso/lib/**' + 'src/main/integration/nutstore/sso/lib/**', + 'src/renderer/src/ui/**' ] } ]) diff --git a/src/renderer/src/pages/discover/hooks/useDiscoverCategories.ts b/src/renderer/src/pages/discover/hooks/useDiscoverCategories.ts index c926f42fe5..6dcc7b4ee6 100644 --- a/src/renderer/src/pages/discover/hooks/useDiscoverCategories.ts +++ b/src/renderer/src/pages/discover/hooks/useDiscoverCategories.ts @@ -16,20 +16,14 @@ const initialCategories: InternalCategory[] = [ title: 'Assistants', path: 'assistant', hasSidebar: false, - items: [ - { id: 'all', name: 'All Assistants' }, - { id: 'gpt3', name: 'GPT-3' } - ] + items: [] }, { id: CherryStoreType.MINI_APP, title: 'Mini Apps', path: 'mini-app', hasSidebar: false, - items: [ - { id: 'all', name: 'All Mini Apps' } - // Add other mini_app subcategories here if any - ] + items: [] } // Add more categories as needed ] @@ -58,12 +52,15 @@ export function useDiscoverCategories() { const categoryFromPath = findCategoryByPath(currentCategoryPath) + // Synchronize active tab with the category determined from the URL path. + // If a category is found from the path, update the active tab to match its ID. if (categoryFromPath) { if (activeTab !== categoryFromPath.id) { setActiveTab(categoryFromPath.id) } } else if (location.pathname === '/discover' || location.pathname === '/discover/') { - // If URL is exactly /discover or /discover/ and no specific category path is matched + // Handle the case where the URL is the base /discover path. + // Redirect to the first category's path to ensure a category is always selected. if (categories.length > 0) { const firstCategory = categories[0] if (firstCategory?.path) { @@ -71,7 +68,9 @@ export function useDiscoverCategories() { } } } else if (!currentCategoryPath && categories.length > 0 && !activeTab) { - // Fallback if no category path in URL and no active tab set yet (e.g. initial load to a bad /discover/xxx url) + // Fallback for invalid or unmatched /discover/xxx URLs. + // If the URL contains a path segment that doesn't correspond to a known category, + // and no tab is active, redirect to the first valid category. const firstCategory = categories[0] if (firstCategory?.path) { navigate(`/discover/${firstCategory.path}?subcategory=all`, { replace: true })