Exclude "local source" for language detection for sources language filter

The local source is always shown, and therefore its language ("other") should only be shown in the language filter in case an actual source is installed that supports is of "other" language.
This commit is contained in:
schroda
2026-01-25 03:51:13 +01:00
parent e63a51e060
commit eace67e464
4 changed files with 29 additions and 5 deletions

View File

@@ -56,6 +56,14 @@ export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
}), }),
[sources, shownLangs], [sources, shownLangs],
); );
const sourcesForLanguageFilter = useMemo(
() =>
SourceService.filter(sources ?? [], {
showNsfw,
keepLocalSource: false,
}),
[sources],
);
const sourcesByLanguage = useMemo(() => { const sourcesByLanguage = useMemo(() => {
const lastUsedSource = SourceService.getLastUsedSource(lastUsedSourceId, filteredSources); const lastUsedSource = SourceService.getLastUsedSource(lastUsedSourceId, filteredSources);
const groupedByLanguageTuple = Object.entries( const groupedByLanguageTuple = Object.entries(
@@ -72,7 +80,10 @@ export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
return groupedByLanguageTuple; return groupedByLanguageTuple;
}, [filteredSources]); }, [filteredSources]);
const sourceLanguages = useMemo(() => SourceService.getLanguages(sources ?? []), [sources]); const sourceLanguages = useMemo(
() => SourceService.getLanguages(sourcesForLanguageFilter, { excludeLocalSource: true }),
[sources],
);
const areSourcesFromDifferentRepos = useMemo( const areSourcesFromDifferentRepos = useMemo(
() => SourceService.areFromMultipleRepos(filteredSources), () => SourceService.areFromMultipleRepos(filteredSources),
[filteredSources], [filteredSources],
@@ -108,10 +119,10 @@ export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
selectedLanguages={shownLangs} selectedLanguages={shownLangs}
setSelectedLanguages={setShownLangs} setSelectedLanguages={setShownLangs}
languages={sourceLanguages} languages={sourceLanguages}
sources={sources ?? []} sources={sourcesForLanguageFilter}
/> />
</>, </>,
[t, shownLangs, sourceLanguages, sources], [t, shownLangs, sourceLanguages, sourcesForLanguageFilter],
); );
if (isLoading) return <LoadingPlaceholder />; if (isLoading) return <LoadingPlaceholder />;

View File

@@ -21,6 +21,7 @@ import { GroupedVirtuoso } from 'react-virtuoso';
import ListItemAvatar from '@mui/material/ListItemAvatar'; import ListItemAvatar from '@mui/material/ListItemAvatar';
import { useLingui } from '@lingui/react/macro'; import { useLingui } from '@lingui/react/macro';
import Checkbox from '@mui/material/Checkbox'; import Checkbox from '@mui/material/Checkbox';
import Box from '@mui/material/Box';
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx'; import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
import { translateExtensionLanguage } from '@/features/extension/Extensions.utils.ts'; import { translateExtensionLanguage } from '@/features/extension/Extensions.utils.ts';
import { languageSortComparator, toUniqueLanguageCodes } from '@/base/utils/Languages.ts'; import { languageSortComparator, toUniqueLanguageCodes } from '@/base/utils/Languages.ts';
@@ -139,6 +140,7 @@ export const SourceLanguageSelect = ({
<Dialog fullWidth maxWidth="xs" open={open} onClose={handleCancel}> <Dialog fullWidth maxWidth="xs" open={open} onClose={handleCancel}>
<DialogTitle>{t`Allowed Languages`}</DialogTitle> <DialogTitle>{t`Allowed Languages`}</DialogTitle>
<DialogContent dividers sx={{ padding: 0 }}> <DialogContent dividers sx={{ padding: 0 }}>
{!languages.length && <Box sx={{ p: 1 }}>{t`No sources installed`}</Box>}
<GroupedVirtuoso <GroupedVirtuoso
style={{ style={{
height: languagesSortedBySelectState.length * 54, height: languagesSortedBySelectState.length * 54,

View File

@@ -46,8 +46,15 @@ export class Sources {
return source.lang; return source.lang;
} }
static getLanguages(sources: (SourceIdInfo & SourceLanguageInfo)[]): string[] { static getLanguages(
return [...new Set(sources.map(Sources.getLanguage))]; sources: (SourceIdInfo & SourceLanguageInfo)[],
{ excludeLocalSource = false }: { excludeLocalSource?: boolean } = {},
): string[] {
const filteredSources = excludeLocalSource
? sources.filter((source) => !Sources.isLocalSource(source))
: sources;
return [...new Set(filteredSources.map(Sources.getLanguage))];
} }
static groupByLanguage<Source extends SourceIdInfo & SourceLanguageInfo & SourceDisplayNameInfo & SourceMetaInfo>( static groupByLanguage<Source extends SourceIdInfo & SourceLanguageInfo & SourceDisplayNameInfo & SourceMetaInfo>(

View File

@@ -2300,6 +2300,10 @@ msgstr "No pages found"
msgid "No sources found. Install Some extensions first." msgid "No sources found. Install Some extensions first."
msgstr "No sources found. Install Some extensions first." msgstr "No sources found. Install Some extensions first."
#: src/features/source/components/SourceLanguageSelect.tsx
msgid "No sources installed"
msgstr "No sources installed"
#: src/features/backup/Backup.utils.ts #: src/features/backup/Backup.utils.ts
#: src/features/category/components/CategoriesInclusionSetting.tsx #: src/features/category/components/CategoriesInclusionSetting.tsx
#: src/features/downloads/screens/DownloadSettings.tsx #: src/features/downloads/screens/DownloadSettings.tsx