2023-01-06 17:34:16 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
|
|
|
/* eslint-disable react/destructuring-assignment */
|
|
|
|
|
/*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { useContext, useEffect } from 'react';
|
|
|
|
|
import NavbarContext from 'components/context/NavbarContext';
|
|
|
|
|
import { Box } from '@mui/system';
|
|
|
|
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
|
|
|
import { requestUpdateServerMetadata } from 'util/metadata';
|
|
|
|
|
import makeToast from 'components/util/Toast';
|
|
|
|
|
import {
|
|
|
|
|
checkAndHandleMissingStoredReaderSettings,
|
|
|
|
|
getDefaultSettings,
|
|
|
|
|
useDefaultReaderSettings,
|
|
|
|
|
} from 'util/readerSettings';
|
|
|
|
|
import ReaderSettingsOptions from 'components/reader/ReaderSettingsOptions';
|
2023-02-24 16:40:37 +01:00
|
|
|
import { IReaderSettings } from 'typings';
|
2023-01-06 17:34:16 +01:00
|
|
|
|
|
|
|
|
export default function DefaultReaderSettings() {
|
|
|
|
|
const { setTitle, setAction } = useContext(NavbarContext);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setTitle('Default Reader Settings');
|
2023-03-11 18:05:58 +01:00
|
|
|
setAction(null);
|
2023-01-06 17:34:16 +01:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const { metadata, settings, loading } = useDefaultReaderSettings();
|
|
|
|
|
|
|
|
|
|
const setSettingValue = (key: keyof IReaderSettings, value: string | boolean) => {
|
2023-02-06 10:06:33 +01:00
|
|
|
requestUpdateServerMetadata(metadata ?? {}, [[key, value]]).catch(() =>
|
|
|
|
|
makeToast('Failed to save the default reader settings to the server', 'warning'),
|
|
|
|
|
);
|
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-02-08 18:19:26 +01:00
|
|
|
checkAndHandleMissingStoredReaderSettings({ meta: 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-01-06 17:34:16 +01:00
|
|
|
readerType={settings.readerType}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|