2023-01-06 17:34:16 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-09-26 15:33:22 +02:00
|
|
|
import { useContext, useLayoutEffect } from 'react';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-10-05 19:44:47 +02:00
|
|
|
import { AllowedMetadataValueTypes } from '@/typings.ts';
|
2024-03-16 16:21:15 +01:00
|
|
|
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/lib/metadata/metadata.ts';
|
2023-01-06 17:34:16 +01:00
|
|
|
import {
|
|
|
|
|
checkAndHandleMissingStoredReaderSettings,
|
|
|
|
|
useDefaultReaderSettings,
|
2024-10-05 19:44:47 +02:00
|
|
|
} from '@/modules/reader/services/ReaderSettingsMetadata.ts';
|
|
|
|
|
import { ReaderSettingsOptions } from '@/modules/reader/components/ReaderSettingsOptions.tsx';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { makeToast } from '@/lib/ui/Toast.ts';
|
2024-10-05 19:44:47 +02:00
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
|
|
|
|
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx';
|
|
|
|
|
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
2024-10-05 19:44:47 +02:00
|
|
|
import { DEFAULT_READER_SETTINGS } from '@/modules/reader/Reader.constants.ts';
|
|
|
|
|
import { IReaderSettings } from '@/modules/reader/Reader.types.ts';
|
2023-01-06 17:34:16 +01:00
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function DefaultReaderSettings() {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2023-10-28 00:32:02 +02:00
|
|
|
const { setTitle, setAction } = useContext(NavBarContext);
|
2024-09-26 15:33:22 +02:00
|
|
|
useLayoutEffect(() => {
|
2023-03-23 13:59:32 +01:00
|
|
|
setTitle(t('reader.settings.title.default_reader_settings'));
|
2023-03-11 18:05:58 +01:00
|
|
|
setAction(null);
|
2024-01-26 20:50:51 +01:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setTitle('');
|
|
|
|
|
setAction(null);
|
|
|
|
|
};
|
2023-03-28 23:14:03 +02:00
|
|
|
}, [t]);
|
2023-01-06 17:34:16 +01:00
|
|
|
|
2024-04-27 22:28:55 +02:00
|
|
|
const {
|
|
|
|
|
metadata,
|
|
|
|
|
settings,
|
|
|
|
|
loading,
|
|
|
|
|
request: { error, refetch },
|
|
|
|
|
} = useDefaultReaderSettings();
|
2023-01-06 17:34:16 +01:00
|
|
|
|
2024-03-18 10:35:35 -07:00
|
|
|
const setSettingValue = (key: keyof IReaderSettings, value: AllowedMetadataValueTypes, persist: boolean = true) => {
|
|
|
|
|
if (persist) {
|
|
|
|
|
requestUpdateServerMetadata([[key, value]]).catch(() =>
|
|
|
|
|
makeToast(t('reader.settings.error.label.failed_to_save_settings'), 'warning'),
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-01-06 17:34:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
2024-04-27 22:28:55 +02:00
|
|
|
return <LoadingPlaceholder />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2023-01-06 17:34:16 +01:00
|
|
|
return (
|
2024-04-29 15:29:33 +02:00
|
|
|
<EmptyViewAbsoluteCentered
|
2024-04-27 22:28:55 +02:00
|
|
|
message={t('global.error.label.failed_to_load_data')}
|
|
|
|
|
messageExtra={error.message}
|
|
|
|
|
retry={() => refetch().catch(defaultPromiseErrorHandler('DefaultReaderSettings::refetch'))}
|
|
|
|
|
/>
|
2023-01-06 17:34:16 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 00:44:01 +02:00
|
|
|
checkAndHandleMissingStoredReaderSettings(
|
|
|
|
|
{ meta: convertToGqlMeta(metadata)! },
|
|
|
|
|
'server',
|
2024-10-05 19:44:47 +02:00
|
|
|
DEFAULT_READER_SETTINGS,
|
2023-12-31 01:42:54 +01:00
|
|
|
).catch(defaultPromiseErrorHandler('DefaultReaderSettings::checkAndHandleMissingStoredReaderSettings'));
|
2023-01-06 17:34:16 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ReaderSettingsOptions
|
|
|
|
|
setSettingValue={setSettingValue}
|
|
|
|
|
staticNav={settings.staticNav}
|
|
|
|
|
showPageNumber={settings.showPageNumber}
|
2023-01-06 18:19:45 +01:00
|
|
|
loadNextOnEnding={settings.loadNextOnEnding}
|
2023-04-05 13:37:12 +02:00
|
|
|
skipDupChapters={settings.skipDupChapters}
|
2023-06-03 20:53:52 +02:00
|
|
|
fitPageToWindow={settings.fitPageToWindow}
|
2024-02-21 02:42:07 +01:00
|
|
|
scalePage={settings.scalePage}
|
2023-01-06 17:34:16 +01:00
|
|
|
readerType={settings.readerType}
|
2023-09-27 18:36:47 -04:00
|
|
|
offsetFirstPage={settings.offsetFirstPage}
|
2024-01-21 13:33:13 -08:00
|
|
|
readerWidth={settings.readerWidth}
|
2023-01-06 17:34:16 +01:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|