Show last used source
This commit is contained in:
@@ -429,6 +429,7 @@
|
|||||||
"horizontal": "Horizontal",
|
"horizontal": "Horizontal",
|
||||||
"info": "Information",
|
"info": "Information",
|
||||||
"large": "Large",
|
"large": "Large",
|
||||||
|
"last_used": "Last used",
|
||||||
"left": "Left",
|
"left": "Left",
|
||||||
"light": "Light",
|
"light": "Light",
|
||||||
"links": "Links",
|
"links": "Links",
|
||||||
|
|||||||
@@ -6,8 +6,11 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SourceIdInfo } from '@/modules/source/Source.types.ts';
|
||||||
|
|
||||||
export type MetadataBrowseSettings = {
|
export type MetadataBrowseSettings = {
|
||||||
hideLibraryEntries: boolean;
|
hideLibraryEntries: boolean;
|
||||||
extensionLanguages: string[];
|
extensionLanguages: string[];
|
||||||
showNsfw: boolean;
|
showNsfw: boolean;
|
||||||
|
lastUsedSourceId: SourceIdInfo['id'] | null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export enum DefaultLanguage {
|
|||||||
OTHER = 'other',
|
OTHER = 'other',
|
||||||
LOCAL_SOURCE = 'localsourcelang',
|
LOCAL_SOURCE = 'localsourcelang',
|
||||||
PINNED = 'pinned',
|
PINNED = 'pinned',
|
||||||
|
LAST_USED_SOURCE = 'last_used_source',
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_LANGUAGE_TO_TRANSLATION: Record<DefaultLanguage, TranslationKey> = {
|
const DEFAULT_LANGUAGE_TO_TRANSLATION: Record<DefaultLanguage, TranslationKey> = {
|
||||||
@@ -22,6 +23,7 @@ const DEFAULT_LANGUAGE_TO_TRANSLATION: Record<DefaultLanguage, TranslationKey> =
|
|||||||
[DefaultLanguage.OTHER]: 'extension.language.other',
|
[DefaultLanguage.OTHER]: 'extension.language.other',
|
||||||
[DefaultLanguage.LOCAL_SOURCE]: 'extension.language.other',
|
[DefaultLanguage.LOCAL_SOURCE]: 'extension.language.other',
|
||||||
[DefaultLanguage.PINNED]: 'global.label.pinned',
|
[DefaultLanguage.PINNED]: 'global.label.pinned',
|
||||||
|
[DefaultLanguage.LAST_USED_SOURCE]: 'global.label.last_used',
|
||||||
};
|
};
|
||||||
|
|
||||||
type LanguageObject = ISOLanguage & { orgCode: string; isoCode: string };
|
type LanguageObject = ISOLanguage & { orgCode: string; isoCode: string };
|
||||||
|
|||||||
@@ -54,4 +54,5 @@ export const extensionLanguageToTranslationKey: { [state in ExtensionGroupState
|
|||||||
[DefaultLanguage.OTHER]: 'extension.language.other',
|
[DefaultLanguage.OTHER]: 'extension.language.other',
|
||||||
[DefaultLanguage.LOCAL_SOURCE]: 'extension.language.other',
|
[DefaultLanguage.LOCAL_SOURCE]: 'extension.language.other',
|
||||||
[DefaultLanguage.PINNED]: 'global.label.pinned',
|
[DefaultLanguage.PINNED]: 'global.label.pinned',
|
||||||
|
[DefaultLanguage.LAST_USED_SOURCE]: 'global.label.last_used',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,9 +49,13 @@ export const isExtensionState = (value: string): boolean =>
|
|||||||
|
|
||||||
export const isExtensionStateOrLanguage = (languageCode: string): boolean =>
|
export const isExtensionStateOrLanguage = (languageCode: string): boolean =>
|
||||||
isExtensionState(languageCode) ||
|
isExtensionState(languageCode) ||
|
||||||
[DefaultLanguage.ALL, DefaultLanguage.OTHER, DefaultLanguage.LOCAL_SOURCE, DefaultLanguage.PINNED].includes(
|
[
|
||||||
languageCode as DefaultLanguage,
|
DefaultLanguage.ALL,
|
||||||
);
|
DefaultLanguage.OTHER,
|
||||||
|
DefaultLanguage.LOCAL_SOURCE,
|
||||||
|
DefaultLanguage.PINNED,
|
||||||
|
DefaultLanguage.LAST_USED_SOURCE,
|
||||||
|
].includes(languageCode as DefaultLanguage);
|
||||||
|
|
||||||
export const translateExtensionLanguage = (languageCode: string): string =>
|
export const translateExtensionLanguage = (languageCode: string): string =>
|
||||||
isExtensionStateOrLanguage(languageCode)
|
isExtensionStateOrLanguage(languageCode)
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export const APP_METADATA_KEY_TO_TYPE = {
|
|||||||
shouldUsePureBlackMode: 'boolean',
|
shouldUsePureBlackMode: 'boolean',
|
||||||
mangaGridItemWidth: 'number',
|
mangaGridItemWidth: 'number',
|
||||||
isPinned: 'boolean',
|
isPinned: 'boolean',
|
||||||
|
lastUsedSourceId: 'string',
|
||||||
} as const satisfies Record<AppMetadataKeys, 'auto' | 'string' | 'number' | 'boolean'>;
|
} as const satisfies Record<AppMetadataKeys, 'auto' | 'string' | 'number' | 'boolean'>;
|
||||||
|
|
||||||
export const VALID_APP_METADATA_KEYS = Object.keys(APP_METADATA_KEY_TO_TYPE);
|
export const VALID_APP_METADATA_KEYS = Object.keys(APP_METADATA_KEY_TO_TYPE);
|
||||||
@@ -147,6 +148,7 @@ export const GLOBAL_METADATA_KEYS: AppMetadataKeys[] = [
|
|||||||
'hideLibraryEntries',
|
'hideLibraryEntries',
|
||||||
'extensionLanguages',
|
'extensionLanguages',
|
||||||
'showNsfw',
|
'showNsfw',
|
||||||
|
'lastUsedSourceId',
|
||||||
|
|
||||||
// history
|
// history
|
||||||
'hideHistory',
|
'hideHistory',
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
|
|||||||
hideLibraryEntries: false,
|
hideLibraryEntries: false,
|
||||||
extensionLanguages: getDefaultLanguages(),
|
extensionLanguages: getDefaultLanguages(),
|
||||||
showNsfw: true,
|
showNsfw: true,
|
||||||
|
lastUsedSourceId: null,
|
||||||
|
|
||||||
// history
|
// history
|
||||||
hideHistory: false,
|
hideHistory: false,
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ import {
|
|||||||
GetSourceMangasFetchMutation,
|
GetSourceMangasFetchMutation,
|
||||||
GetSourceMangasFetchMutationVariables,
|
GetSourceMangasFetchMutationVariables,
|
||||||
} from '@/lib/graphql/generated/graphql.ts';
|
} from '@/lib/graphql/generated/graphql.ts';
|
||||||
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
import {
|
||||||
|
updateMetadataServerSettings,
|
||||||
|
useMetadataServerSettings,
|
||||||
|
} from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
import { useLocalStorage, useSessionStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { useLocalStorage, useSessionStorage } from '@/modules/core/hooks/useStorage.tsx';
|
||||||
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
||||||
import { getGridSnapshotKey } from '@/modules/manga/components/MangaGrid.tsx';
|
import { getGridSnapshotKey } from '@/modules/manga/components/MangaGrid.tsx';
|
||||||
@@ -382,6 +385,12 @@ export function SourceMangas() {
|
|||||||
setFiltersToApply([]);
|
setFiltersToApply([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
updateMetadataServerSettings('lastUsedSourceId', sourceId).catch(
|
||||||
|
defaultPromiseErrorHandler('SourceMangas::setLastUsedSourceId'),
|
||||||
|
);
|
||||||
|
}, [sourceId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (filteredOutAllItemsOfFetchedPage && hasNextPage && !loading) {
|
if (filteredOutAllItemsOfFetchedPage && hasNextPage && !loading) {
|
||||||
loadPage(lastPageNum + 1);
|
loadPage(lastPageNum + 1);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
||||||
import { getDefaultLanguages } from '@/modules/core/utils/Languages.ts';
|
import { DefaultLanguage, getDefaultLanguages } from '@/modules/core/utils/Languages.ts';
|
||||||
import { LoadingPlaceholder } from '@/modules/core/components/feedback/LoadingPlaceholder.tsx';
|
import { LoadingPlaceholder } from '@/modules/core/components/feedback/LoadingPlaceholder.tsx';
|
||||||
import { SourceCard } from '@/modules/source/components/SourceCard.tsx';
|
import { SourceCard } from '@/modules/source/components/SourceCard.tsx';
|
||||||
import { LanguageSelect } from '@/modules/core/components/inputs/LanguageSelect.tsx';
|
import { LanguageSelect } from '@/modules/core/components/inputs/LanguageSelect.tsx';
|
||||||
@@ -33,7 +33,7 @@ export function Sources() {
|
|||||||
|
|
||||||
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
||||||
const {
|
const {
|
||||||
settings: { showNsfw },
|
settings: { showNsfw, lastUsedSourceId },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -47,10 +47,19 @@ export function Sources() {
|
|||||||
() => SourceService.filter(sources ?? [], { showNsfw, languages: shownLangs, keepLocalSource: true }),
|
() => SourceService.filter(sources ?? [], { showNsfw, languages: shownLangs, keepLocalSource: true }),
|
||||||
[sources, shownLangs],
|
[sources, shownLangs],
|
||||||
);
|
);
|
||||||
const sourcesByLanguageTuple = useMemo(
|
const sourcesByLanguage = useMemo(() => {
|
||||||
() => Object.entries(SourceService.groupByLanguage(filteredSources)),
|
const lastUsedSource = SourceService.getLastUsedSource(lastUsedSourceId, filteredSources);
|
||||||
[filteredSources],
|
const groupedByLanguageTuple = Object.entries(SourceService.groupByLanguage(filteredSources));
|
||||||
);
|
|
||||||
|
if (lastUsedSource) {
|
||||||
|
return [
|
||||||
|
[DefaultLanguage.LAST_USED_SOURCE, [lastUsedSource]],
|
||||||
|
...groupedByLanguageTuple,
|
||||||
|
] satisfies typeof groupedByLanguageTuple;
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupedByLanguageTuple;
|
||||||
|
}, [filteredSources]);
|
||||||
|
|
||||||
const sourceLanguages = useMemo(() => SourceService.getLanguages(sources ?? []), [sources]);
|
const sourceLanguages = useMemo(() => SourceService.getLanguages(sources ?? []), [sources]);
|
||||||
const areSourcesFromDifferentRepos = useMemo(
|
const areSourcesFromDifferentRepos = useMemo(
|
||||||
@@ -94,10 +103,10 @@ export function Sources() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{sourcesByLanguageTuple.map(([languages, sourcesOfLanguage]) => (
|
{sourcesByLanguage.map(([language, sourcesOfLanguage]) => (
|
||||||
<Fragment key={languages}>
|
<Fragment key={language}>
|
||||||
<Typography
|
<Typography
|
||||||
key={languages}
|
key={language}
|
||||||
variant="h5"
|
variant="h5"
|
||||||
component="h2"
|
component="h2"
|
||||||
sx={{
|
sx={{
|
||||||
@@ -107,7 +116,7 @@ export function Sources() {
|
|||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{translateExtensionLanguage(languages)}
|
{translateExtensionLanguage(language)}
|
||||||
</Typography>
|
</Typography>
|
||||||
{sourcesOfLanguage.map((source) => (
|
{sourcesOfLanguage.map((source) => (
|
||||||
<SourceCard key={source.id} source={source} showSourceRepo={areSourcesFromDifferentRepos} />
|
<SourceCard key={source.id} source={source} showSourceRepo={areSourcesFromDifferentRepos} />
|
||||||
|
|||||||
@@ -109,4 +109,11 @@ export class Sources {
|
|||||||
|
|
||||||
return sources.some((source) => source.extension.repo !== repo && !Sources.isLocalSource(source));
|
return sources.some((source) => source.extension.repo !== repo && !Sources.isLocalSource(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getLastUsedSource<Source extends SourceIdInfo & SourceMetaInfo>(
|
||||||
|
lastUsedSourceId: SourceIdInfo['id'] | null,
|
||||||
|
sources: Source[],
|
||||||
|
): Source | undefined {
|
||||||
|
return sources.find((source) => source.id === lastUsedSourceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user