Handle "local source" as source with language "other"
Same as in mihon
This commit is contained in:
@@ -15,7 +15,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { useLocalStorage } from '@/util/useStorage.tsx';
|
import { useLocalStorage } from '@/util/useStorage.tsx';
|
||||||
import { sourceDefualtLangs, sourceForcedDefaultLangs, langSortCmp } from '@/util/language';
|
import { sourceDefualtLangs, sourceForcedDefaultLangs, langSortCmp, DefaultLanguage } from '@/util/language';
|
||||||
import { translateExtensionLanguage } from '@/screens/util/Extensions';
|
import { translateExtensionLanguage } from '@/screens/util/Extensions';
|
||||||
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
|
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
|
||||||
import { SourceCard } from '@/components/SourceCard';
|
import { SourceCard } from '@/components/SourceCard';
|
||||||
@@ -25,26 +25,28 @@ import { EmptyViewAbsoluteCentered } from '@/components/util/EmptyViewAbsoluteCe
|
|||||||
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
||||||
import { SourceType } from '@/lib/graphql/generated/graphql.ts';
|
import { SourceType } from '@/lib/graphql/generated/graphql.ts';
|
||||||
|
|
||||||
function sourceToLangList(sources: Pick<SourceType, 'lang'>[]) {
|
function sourceToLangList(sources: Pick<SourceType, 'id' | 'lang'>[]) {
|
||||||
const result: string[] = [];
|
const result = new Set<string>();
|
||||||
|
|
||||||
sources.forEach((source) => {
|
sources.forEach((source) => {
|
||||||
if (result.indexOf(source.lang) === -1) {
|
const isLocalSource = Number(source.id) === 0;
|
||||||
result.push(source.lang);
|
const lang = isLocalSource ? DefaultLanguage.OTHER : source.lang;
|
||||||
}
|
|
||||||
|
result.add(lang);
|
||||||
});
|
});
|
||||||
|
|
||||||
result.sort(langSortCmp);
|
return [...result].sort(langSortCmp);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function groupByLang<Source extends Pick<SourceType, 'lang'>>(sources: Source[]): Record<string, Source[]> {
|
function groupByLang<Source extends Pick<SourceType, 'id' | 'lang'>>(sources: Source[]): Record<string, Source[]> {
|
||||||
const result: Record<string, Source[]> = {};
|
const result: Record<string, Source[]> = {};
|
||||||
|
|
||||||
sources.forEach((source) => {
|
sources.forEach((source) => {
|
||||||
if (result[source.lang] === undefined) {
|
const isLocalSource = Number(source.id) === 0;
|
||||||
result[source.lang] = [];
|
const lang = isLocalSource ? DefaultLanguage.OTHER : source.lang;
|
||||||
}
|
|
||||||
result[source.lang].push(source);
|
result[lang] ??= [];
|
||||||
|
result[lang].push(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -136,7 +138,7 @@ export function Sources() {
|
|||||||
.sort((a, b) => langSortCmp(a[0], b[0]))
|
.sort((a, b) => langSortCmp(a[0], b[0]))
|
||||||
.map(
|
.map(
|
||||||
([lang, list]) =>
|
([lang, list]) =>
|
||||||
shownLangs.indexOf(lang) !== -1 && (
|
(lang === DefaultLanguage.OTHER || shownLangs.includes(lang)) && (
|
||||||
<Fragment key={lang}>
|
<Fragment key={lang}>
|
||||||
<Typography
|
<Typography
|
||||||
key={lang}
|
key={lang}
|
||||||
@@ -152,7 +154,20 @@ export function Sources() {
|
|||||||
{translateExtensionLanguage(lang)}
|
{translateExtensionLanguage(lang)}
|
||||||
</Typography>
|
</Typography>
|
||||||
{list
|
{list
|
||||||
.filter((source) => showNsfw || !source.isNsfw)
|
.filter((source) => {
|
||||||
|
const isLangOther = lang === DefaultLanguage.OTHER;
|
||||||
|
if (isLangOther) {
|
||||||
|
const isLocalSource = Number(source.id) === 0;
|
||||||
|
const isLangShown = shownLangs.includes(lang);
|
||||||
|
|
||||||
|
const isLangOtherSourceShown = isLangShown || isLocalSource;
|
||||||
|
if (!isLangOtherSourceShown) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return showNsfw || !source.isNsfw;
|
||||||
|
})
|
||||||
.map((source) => (
|
.map((source) => (
|
||||||
<SourceCard
|
<SourceCard
|
||||||
key={source.id}
|
key={source.id}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export const extensionLanguageToTranslationKey: { [state in ExtensionState | Def
|
|||||||
[ExtensionState.OBSOLETE]: 'extension.state.label.obsolete',
|
[ExtensionState.OBSOLETE]: 'extension.state.label.obsolete',
|
||||||
[DefaultLanguage.ALL]: 'extension.language.all',
|
[DefaultLanguage.ALL]: 'extension.language.all',
|
||||||
[DefaultLanguage.OTHER]: 'extension.language.other',
|
[DefaultLanguage.OTHER]: 'extension.language.other',
|
||||||
[DefaultLanguage.LOCAL_SOURCE]: 'source.local_source.title',
|
[DefaultLanguage.LOCAL_SOURCE]: 'extension.language.other',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isExtensionStateOrLanguage = (languageCode: string): boolean =>
|
export const isExtensionStateOrLanguage = (languageCode: string): boolean =>
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ export const langSortCmp = (a: string, b: string) => {
|
|||||||
|
|
||||||
if (a === 'en') return -1;
|
if (a === 'en') return -1;
|
||||||
if (b === 'en') return 1;
|
if (b === 'en') return 1;
|
||||||
if (a === DefaultLanguage.LOCAL_SOURCE) return 1;
|
|
||||||
if (b === DefaultLanguage.LOCAL_SOURCE) return -1;
|
|
||||||
|
|
||||||
return aLang > bLang ? 1 : -1;
|
return aLang > bLang ? 1 : -1;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user