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.
This commit is contained in:
@@ -54,6 +54,7 @@ import { getSourceMetadata } from '@/modules/source/services/SourceMetadata.ts';
|
|||||||
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
||||||
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
||||||
import { MUIUtil } from '@/lib/mui/MUI.util.ts';
|
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 SourceLoadingState = { isLoading: boolean; hasResults: boolean; emptySearch: boolean; error: any };
|
||||||
type SourceToLoadingStateMap = Map<string, SourceLoadingState>;
|
type SourceToLoadingStateMap = Map<string, SourceLoadingState>;
|
||||||
@@ -119,12 +120,14 @@ const SourceSearchPreview = React.memo(
|
|||||||
searchString,
|
searchString,
|
||||||
emptyQuery,
|
emptyQuery,
|
||||||
mode,
|
mode,
|
||||||
|
shouldShowOnlySourcesWithResults,
|
||||||
}: {
|
}: {
|
||||||
source: SourceIdInfo & SourceDisplayNameInfo & SourceNameInfo & SourceLanguageInfo;
|
source: SourceIdInfo & SourceDisplayNameInfo & SourceNameInfo & SourceLanguageInfo;
|
||||||
onSearchRequestFinished: (source: SourceIdInfo, state: SourceLoadingState) => void;
|
onSearchRequestFinished: (source: SourceIdInfo, state: SourceLoadingState) => void;
|
||||||
searchString: string | null | undefined;
|
searchString: string | null | undefined;
|
||||||
emptyQuery: boolean;
|
emptyQuery: boolean;
|
||||||
} & Pick<MangaCardProps, 'mode'>) => {
|
} & Pick<MangaCardProps, 'mode'> &
|
||||||
|
Pick<MetadataBrowseSettings, 'shouldShowOnlySourcesWithResults'>) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { id, name, lang } = source;
|
const { id, name, lang } = source;
|
||||||
@@ -169,8 +172,12 @@ const SourceSearchPreview = React.memo(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldShowOnlySourcesWithResults && (noMangasFound || error)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Box sx={{ pb: 2 }}>
|
||||||
<Card sx={{ mb: 1 }}>
|
<Card sx={{ mb: 1 }}>
|
||||||
<CardActionArea
|
<CardActionArea
|
||||||
component={Link}
|
component={Link}
|
||||||
@@ -219,7 +226,7 @@ const SourceSearchPreview = React.memo(
|
|||||||
mode={mode}
|
mode={mode}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</Box>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -261,21 +268,7 @@ export const SearchAll: React.FC = () => {
|
|||||||
}),
|
}),
|
||||||
[sources, shownLangs, shouldShowOnlyPinnedSources],
|
[sources, shownLangs, shouldShowOnlyPinnedSources],
|
||||||
);
|
);
|
||||||
const filteredSourcesByHasResult = useMemo(() => {
|
const sourcesSortedByName = useMemo(() => [...filteredSources].toSorted(compareSourceByName), [filteredSources]);
|
||||||
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 sourcesSortedByResult = useMemo(
|
const sourcesSortedByResult = useMemo(
|
||||||
() =>
|
() =>
|
||||||
[...sourcesSortedByName].sort((sourceA, sourceB) =>
|
[...sourcesSortedByName].sort((sourceA, sourceB) =>
|
||||||
@@ -368,16 +361,16 @@ export const SearchAll: React.FC = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box sx={{ pt: `${filterHeaderHeight}px` }}>
|
<Box sx={{ pt: `${filterHeaderHeight}px` }}>
|
||||||
{sourcesSortedByResult.map((source, index) => (
|
{sourcesSortedByResult.map((source) => (
|
||||||
<Box key={source.id} sx={{ pb: index + 1 !== sourcesSortedByResult.length ? 2 : 0 }}>
|
<SourceSearchPreview
|
||||||
<SourceSearchPreview
|
key={source.id}
|
||||||
source={source}
|
source={source}
|
||||||
onSearchRequestFinished={updateSourceLoadingState}
|
onSearchRequestFinished={updateSourceLoadingState}
|
||||||
searchString={searchString}
|
searchString={searchString}
|
||||||
emptyQuery={!query}
|
emptyQuery={!query}
|
||||||
mode={isMigrateMode ? 'migrate.select' : 'source'}
|
mode={isMigrateMode ? 'migrate.select' : 'source'}
|
||||||
/>
|
shouldShowOnlySourcesWithResults={shouldShowOnlySourcesWithResults}
|
||||||
</Box>
|
/>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user