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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-14 21:43:06 +02:00
|
|
|
import { useContext, useEffect } from 'react';
|
2023-06-04 21:08:39 +02:00
|
|
|
import { Box } from '@mui/material';
|
2023-01-06 17:34:16 +01:00
|
|
|
import CircularProgress from '@mui/material/CircularProgress';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { IReaderSettings } from '@/typings';
|
2023-09-08 00:44:01 +02:00
|
|
|
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/util/metadata';
|
2023-01-06 17:34:16 +01:00
|
|
|
import {
|
|
|
|
|
checkAndHandleMissingStoredReaderSettings,
|
|
|
|
|
getDefaultSettings,
|
|
|
|
|
useDefaultReaderSettings,
|
2023-06-05 01:42:39 +02:00
|
|
|
} from '@/util/readerSettings';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { ReaderSettingsOptions } from '@/components/reader/ReaderSettingsOptions';
|
|
|
|
|
import { makeToast } from '@/components/util/Toast';
|
|
|
|
|
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext';
|
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);
|
2023-01-06 17:34:16 +01:00
|
|
|
useEffect(() => {
|
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);
|
2023-03-28 23:14:03 +02:00
|
|
|
}, [t]);
|
2023-01-06 17:34:16 +01:00
|
|
|
|
|
|
|
|
const { metadata, settings, loading } = useDefaultReaderSettings();
|
|
|
|
|
|
2023-06-26 20:40:35 +02:00
|
|
|
useSetDefaultBackTo('settings');
|
|
|
|
|
|
2023-01-06 17:34:16 +01:00
|
|
|
const setSettingValue = (key: keyof IReaderSettings, value: string | boolean) => {
|
2023-09-08 00:44:01 +02:00
|
|
|
requestUpdateServerMetadata(convertToGqlMeta(metadata)! ?? {}, [[key, value]]).catch(() =>
|
2023-03-23 13:59:32 +01:00
|
|
|
makeToast(t('reader.settings.error.label.failed_to_save_settings'), 'warning'),
|
2023-02-06 10:06:33 +01:00
|
|
|
);
|
2023-01-06 17:34:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
2023-02-06 10:06:33 +01:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
height: '100vh',
|
|
|
|
|
width: '100vw',
|
|
|
|
|
display: 'grid',
|
|
|
|
|
placeItems: 'center',
|
|
|
|
|
}}
|
2023-01-06 17:34:16 +01:00
|
|
|
>
|
|
|
|
|
<CircularProgress thickness={5} />
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 00:44:01 +02:00
|
|
|
checkAndHandleMissingStoredReaderSettings(
|
|
|
|
|
{ meta: convertToGqlMeta(metadata)! },
|
|
|
|
|
'server',
|
|
|
|
|
getDefaultSettings(),
|
|
|
|
|
).catch(() => {});
|
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}
|
2023-01-06 17:34:16 +01:00
|
|
|
readerType={settings.readerType}
|
2023-09-27 18:36:47 -04:00
|
|
|
offsetFirstPage={settings.offsetFirstPage}
|
2023-01-06 17:34:16 +01:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|