From e0fb835f916397a020a999f86b07bc23fe48d928 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 23 May 2025 00:27:57 +0200 Subject: [PATCH] Fix "search all" with "show results only" enabled After a source did not have any results for a performed search, a follow-up search was not possible anymore, due to the source being filtered out of the rendered sources. --- .../global-search/screens/SearchAll.tsx | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/modules/global-search/screens/SearchAll.tsx b/src/modules/global-search/screens/SearchAll.tsx index cc689ff3..e978feb6 100644 --- a/src/modules/global-search/screens/SearchAll.tsx +++ b/src/modules/global-search/screens/SearchAll.tsx @@ -54,6 +54,7 @@ import { getSourceMetadata } from '@/modules/source/services/SourceMetadata.ts'; import { makeToast } from '@/modules/core/utils/Toast.ts'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { MUIUtil } from '@/lib/mui/MUI.util.ts'; +import { MetadataBrowseSettings } from '@/modules/browse/Browse.types.ts'; type SourceLoadingState = { isLoading: boolean; hasResults: boolean; emptySearch: boolean; error: any }; type SourceToLoadingStateMap = Map; @@ -119,12 +120,14 @@ const SourceSearchPreview = React.memo( searchString, emptyQuery, mode, + shouldShowOnlySourcesWithResults, }: { source: SourceIdInfo & SourceDisplayNameInfo & SourceNameInfo & SourceLanguageInfo; onSearchRequestFinished: (source: SourceIdInfo, state: SourceLoadingState) => void; searchString: string | null | undefined; emptyQuery: boolean; - } & Pick) => { + } & Pick & + Pick) => { const { t } = useTranslation(); const { id, name, lang } = source; @@ -169,8 +172,12 @@ const SourceSearchPreview = React.memo( return null; } + if (shouldShowOnlySourcesWithResults && (noMangasFound || error)) { + return null; + } + return ( - <> + )} - + ); }, ); @@ -261,21 +268,7 @@ export const SearchAll: React.FC = () => { }), [sources, shownLangs, shouldShowOnlyPinnedSources], ); - const filteredSourcesByHasResult = useMemo(() => { - if (!shouldShowOnlySourcesWithResults) { - return filteredSources; - } - - return filteredSources.filter((source) => { - const sourceState = debouncedSourceToLoadingStateMap.get(source.id); - - return !sourceState || sourceState?.isLoading || (sourceState?.hasResults && !sourceState?.error); - }); - }, [filteredSources, shouldShowOnlySourcesWithResults, debouncedSourceToLoadingStateMap]); - const sourcesSortedByName = useMemo( - () => [...filteredSourcesByHasResult].toSorted(compareSourceByName), - [filteredSourcesByHasResult], - ); + const sourcesSortedByName = useMemo(() => [...filteredSources].toSorted(compareSourceByName), [filteredSources]); const sourcesSortedByResult = useMemo( () => [...sourcesSortedByName].sort((sourceA, sourceB) => @@ -368,16 +361,16 @@ export const SearchAll: React.FC = () => { - {sourcesSortedByResult.map((source, index) => ( - - - + {sourcesSortedByResult.map((source) => ( + ))}