make default reader settings changeable (#217)
* [#214] Move "reader settings" util functions into new file * [#214] Extract "options" of "ReaderSettings" to new component * [#214] Add component for changing the default reader settings * [#214] Add default "ReaderSettings" to "Settings" * [#214] Use default "ReaderSettings" stored on the server Wait for both "manga" and "defaultSettings" to be loaded. Otherwise, by the time the "manga" response was received, the "defaultSettings" might be still loading and thus, the local fallback "default" settings will get used as the "default settings" * [#214] Save and update "ReaderSettings" options in case they are missing - Manga gets read the first time => save settings in metadata - Default settings get opened the first time => save settings in global metadata
This commit is contained in:
60
src/screens/settings/DefaultReaderSettings.tsx
Normal file
60
src/screens/settings/DefaultReaderSettings.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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';
|
||||
|
||||
export default function DefaultReaderSettings() {
|
||||
const { setTitle, setAction } = useContext(NavbarContext);
|
||||
useEffect(() => {
|
||||
setTitle('Default Reader Settings');
|
||||
setAction(<></>);
|
||||
}, []);
|
||||
|
||||
const { metadata, settings, loading } = useDefaultReaderSettings();
|
||||
|
||||
const setSettingValue = (key: keyof IReaderSettings, value: string | boolean) => {
|
||||
requestUpdateServerMetadata(metadata ?? {}, [[key, value]]).catch(() => makeToast('Failed to save the default reader settings to the server', 'warning'));
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Box sx={{
|
||||
height: '100vh', width: '100vw', display: 'grid', placeItems: 'center',
|
||||
}}
|
||||
>
|
||||
<CircularProgress thickness={5} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
checkAndHandleMissingStoredReaderSettings({ meta: metadata }, 'server', getDefaultSettings())
|
||||
.catch(() => {});
|
||||
|
||||
return (
|
||||
<ReaderSettingsOptions
|
||||
setSettingValue={setSettingValue}
|
||||
staticNav={settings.staticNav}
|
||||
showPageNumber={settings.showPageNumber}
|
||||
loadNextonEnding={settings.loadNextonEnding}
|
||||
readerType={settings.readerType}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user