Save selected source languages on the server
This commit is contained in:
@@ -11,6 +11,7 @@ import { SourceIdInfo } from '@/modules/source/Source.types.ts';
|
|||||||
export type MetadataBrowseSettings = {
|
export type MetadataBrowseSettings = {
|
||||||
hideLibraryEntries: boolean;
|
hideLibraryEntries: boolean;
|
||||||
extensionLanguages: string[];
|
extensionLanguages: string[];
|
||||||
|
sourceLanguages: string[];
|
||||||
showNsfw: boolean;
|
showNsfw: boolean;
|
||||||
lastUsedSourceId: SourceIdInfo['id'] | null;
|
lastUsedSourceId: SourceIdInfo['id'] | null;
|
||||||
shouldShowOnlySourcesWithResults: boolean;
|
shouldShowOnlySourcesWithResults: boolean;
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import { useElementSize } from '@mantine/hooks';
|
|||||||
import IconButton from '@mui/material/IconButton'; // ms
|
import IconButton from '@mui/material/IconButton'; // ms
|
||||||
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
|
||||||
import { getDefaultLanguages } from '@/modules/core/utils/Languages.ts';
|
|
||||||
import { AppbarSearch } from '@/modules/core/components/AppbarSearch.tsx';
|
import { AppbarSearch } from '@/modules/core/components/AppbarSearch.tsx';
|
||||||
import { LanguageSelect } from '@/modules/core/components/inputs/LanguageSelect.tsx';
|
import { LanguageSelect } from '@/modules/core/components/inputs/LanguageSelect.tsx';
|
||||||
import { useDebounce } from '@/modules/core/hooks/useDebounce.ts';
|
import { useDebounce } from '@/modules/core/hooks/useDebounce.ts';
|
||||||
@@ -243,7 +241,7 @@ export const SearchAll: React.FC = () => {
|
|||||||
const [query] = useQueryParam('query', StringParam);
|
const [query] = useQueryParam('query', StringParam);
|
||||||
const searchString = useDebounce(query, TRIGGER_SEARCH_THRESHOLD);
|
const searchString = useDebounce(query, TRIGGER_SEARCH_THRESHOLD);
|
||||||
|
|
||||||
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
const { languages: shownLangs, setLanguages: setShownLangs } = Sources.useLanguages();
|
||||||
const {
|
const {
|
||||||
settings: { showNsfw, shouldShowOnlySourcesWithResults },
|
settings: { showNsfw, shouldShowOnlySourcesWithResults },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export const APP_METADATA_KEY_TO_TYPE = {
|
|||||||
unread: 'auto', // boolean undefined null
|
unread: 'auto', // boolean undefined null
|
||||||
showChapterNumber: 'boolean',
|
showChapterNumber: 'boolean',
|
||||||
extensionLanguages: 'string', // string[]
|
extensionLanguages: 'string', // string[]
|
||||||
|
sourceLanguages: 'string', // string[]
|
||||||
showNsfw: 'boolean',
|
showNsfw: 'boolean',
|
||||||
shouldUseInfiniteScroll: 'boolean',
|
shouldUseInfiniteScroll: 'boolean',
|
||||||
shouldShowTransitionPage: 'boolean',
|
shouldShowTransitionPage: 'boolean',
|
||||||
@@ -150,6 +151,7 @@ export const GLOBAL_METADATA_KEYS: AppMetadataKeys[] = [
|
|||||||
// browse
|
// browse
|
||||||
'hideLibraryEntries',
|
'hideLibraryEntries',
|
||||||
'extensionLanguages',
|
'extensionLanguages',
|
||||||
|
'sourceLanguages',
|
||||||
'showNsfw',
|
'showNsfw',
|
||||||
'lastUsedSourceId',
|
'lastUsedSourceId',
|
||||||
'shouldShowOnlySourcesWithResults',
|
'shouldShowOnlySourcesWithResults',
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
|
|||||||
// browse
|
// browse
|
||||||
hideLibraryEntries: false,
|
hideLibraryEntries: false,
|
||||||
extensionLanguages: getDefaultLanguages(),
|
extensionLanguages: getDefaultLanguages(),
|
||||||
|
sourceLanguages: getDefaultLanguages(),
|
||||||
showNsfw: true,
|
showNsfw: true,
|
||||||
lastUsedSourceId: null,
|
lastUsedSourceId: null,
|
||||||
shouldShowOnlySourcesWithResults: true,
|
shouldShowOnlySourcesWithResults: true,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const convertSettingsToMetadata = (
|
|||||||
customThemes: JSON.stringify(settings.customThemes),
|
customThemes: JSON.stringify(settings.customThemes),
|
||||||
migrateSortSettings: JSON.stringify(settings.migrateSortSettings),
|
migrateSortSettings: JSON.stringify(settings.migrateSortSettings),
|
||||||
extensionLanguages: JSON.stringify(settings.extensionLanguages),
|
extensionLanguages: JSON.stringify(settings.extensionLanguages),
|
||||||
|
sourceLanguages: JSON.stringify(settings.sourceLanguages),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const convertMetadataToSettings = (
|
export const convertMetadataToSettings = (
|
||||||
@@ -47,6 +48,9 @@ export const convertMetadataToSettings = (
|
|||||||
extensionLanguages:
|
extensionLanguages:
|
||||||
jsonSaveParse<string[]>((metadata.extensionLanguages as string) ?? '') ??
|
jsonSaveParse<string[]>((metadata.extensionLanguages as string) ?? '') ??
|
||||||
SERVER_SETTINGS_METADATA_DEFAULT.extensionLanguages,
|
SERVER_SETTINGS_METADATA_DEFAULT.extensionLanguages,
|
||||||
|
sourceLanguages:
|
||||||
|
jsonSaveParse<string[]>((metadata.sourceLanguages as string) ?? '') ??
|
||||||
|
SERVER_SETTINGS_METADATA_DEFAULT.sourceLanguages,
|
||||||
}) satisfies MetadataServerSettings;
|
}) satisfies MetadataServerSettings;
|
||||||
|
|
||||||
const getMetadataServerSettingsWithDefaultFallback = (
|
const getMetadataServerSettingsWithDefaultFallback = (
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
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 { DefaultLanguage } 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';
|
||||||
@@ -35,7 +34,7 @@ import { StyledGroupItemWrapper } from '@/modules/core/components/virtuoso/Style
|
|||||||
export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
|
export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
const { languages: shownLangs, setLanguages: setShownLangs } = SourceService.useLanguages();
|
||||||
const {
|
const {
|
||||||
settings: { showNsfw, lastUsedSourceId },
|
settings: { showNsfw, lastUsedSourceId },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
* 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 { useTranslation } from 'react-i18next';
|
||||||
|
import { useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
SourceDisplayNameInfo,
|
SourceDisplayNameInfo,
|
||||||
SourceIdInfo,
|
SourceIdInfo,
|
||||||
@@ -22,6 +24,12 @@ import {
|
|||||||
toUniqueLanguageCodes,
|
toUniqueLanguageCodes,
|
||||||
} from '@/modules/core/utils/Languages.ts';
|
} from '@/modules/core/utils/Languages.ts';
|
||||||
import { getSourceMetadata } from '@/modules/source/services/SourceMetadata.ts';
|
import { getSourceMetadata } from '@/modules/source/services/SourceMetadata.ts';
|
||||||
|
import {
|
||||||
|
createUpdateMetadataServerSettings,
|
||||||
|
useMetadataServerSettings,
|
||||||
|
} from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
|
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
||||||
|
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||||
|
|
||||||
export class Sources {
|
export class Sources {
|
||||||
static readonly LOCAL_SOURCE_ID = '0';
|
static readonly LOCAL_SOURCE_ID = '0';
|
||||||
@@ -138,4 +146,24 @@ export class Sources {
|
|||||||
): Source | undefined {
|
): Source | undefined {
|
||||||
return sources.find((source) => source.id === lastUsedSourceId);
|
return sources.find((source) => source.id === lastUsedSourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static useLanguages(): {
|
||||||
|
languages: string[];
|
||||||
|
setLanguages: (languages: string[]) => void;
|
||||||
|
} {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const {
|
||||||
|
settings: { sourceLanguages },
|
||||||
|
} = useMetadataServerSettings();
|
||||||
|
|
||||||
|
const updateSetting = createUpdateMetadataServerSettings<'sourceLanguages'>((e) =>
|
||||||
|
makeToast(t('global.error.label.failed_to_save_changes', getErrorMessage(e)), 'error'),
|
||||||
|
);
|
||||||
|
const setLanguages = useCallback((languages: string[]) => updateSetting('sourceLanguages', languages), []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
languages: sourceLanguages,
|
||||||
|
setLanguages,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user