2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-02-20 01:23:52 +03:30
|
|
|
* 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/. */
|
|
|
|
|
|
2021-03-09 16:44:09 +03:30
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2023-01-06 17:34:16 +01:00
|
|
|
import AutoStoriesIcon from '@mui/icons-material/AutoStories';
|
2021-09-09 17:51:22 +04:30
|
|
|
import List from '@mui/material/List';
|
|
|
|
|
import ListAltIcon from '@mui/icons-material/ListAlt';
|
|
|
|
|
import BackupIcon from '@mui/icons-material/Backup';
|
|
|
|
|
import Brightness6Icon from '@mui/icons-material/Brightness6';
|
|
|
|
|
import DnsIcon from '@mui/icons-material/Dns';
|
|
|
|
|
import EditIcon from '@mui/icons-material/Edit';
|
|
|
|
|
import InfoIcon from '@mui/icons-material/Info';
|
2021-09-18 20:59:23 +04:30
|
|
|
import CachedIcon from '@mui/icons-material/Cached';
|
2021-09-09 17:51:22 +04:30
|
|
|
import ListItem from '@mui/material/ListItem';
|
|
|
|
|
import ListItemIcon from '@mui/material/ListItemIcon';
|
|
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
|
|
|
|
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
|
|
|
|
|
import Switch from '@mui/material/Switch';
|
|
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
|
import Dialog from '@mui/material/Dialog';
|
|
|
|
|
import DialogActions from '@mui/material/DialogActions';
|
|
|
|
|
import DialogContent from '@mui/material/DialogContent';
|
|
|
|
|
import DialogContentText from '@mui/material/DialogContentText';
|
|
|
|
|
import TextField from '@mui/material/TextField';
|
|
|
|
|
import FavoriteIcon from '@mui/icons-material/Favorite';
|
2022-04-02 01:34:10 +01:00
|
|
|
import Slider from '@mui/material/Slider';
|
2023-03-25 19:34:05 +01:00
|
|
|
import { DialogTitle, ListItemButton, MenuItem, Select } from '@mui/material';
|
2022-04-02 01:34:10 +01:00
|
|
|
import ViewModuleIcon from '@mui/icons-material/ViewModule';
|
2023-02-05 16:15:20 +01:00
|
|
|
import NavbarContext from 'components/context/NavbarContext';
|
|
|
|
|
import DarkTheme from 'components/context/DarkTheme';
|
|
|
|
|
import useLocalStorage from 'util/useLocalStorage';
|
|
|
|
|
import ListItemLink from 'components/util/ListItemLink';
|
2023-03-04 22:21:24 +05:30
|
|
|
import SearchSettings from 'screens/settings/SearchSettings';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-03-25 19:34:05 +01:00
|
|
|
import LanguageIcon from '@mui/icons-material/Language';
|
|
|
|
|
import { langCodeToName } from 'util/language';
|
2021-02-20 01:23:52 +03:30
|
|
|
|
|
|
|
|
export default function Settings() {
|
2023-03-25 19:34:05 +01:00
|
|
|
const { t, i18n } = useTranslation();
|
2023-03-23 13:59:32 +01:00
|
|
|
|
2021-03-09 16:44:09 +03:30
|
|
|
const { setTitle, setAction } = useContext(NavbarContext);
|
2023-02-06 10:06:33 +01:00
|
|
|
useEffect(() => {
|
2023-03-23 13:59:32 +01:00
|
|
|
setTitle(t('settings.title'));
|
2023-03-11 18:05:58 +01:00
|
|
|
setAction(null);
|
2023-02-06 10:06:33 +01:00
|
|
|
}, []);
|
2021-03-09 16:44:09 +03:30
|
|
|
|
2021-02-20 02:57:52 +03:30
|
|
|
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
|
2021-03-07 22:25:29 +03:30
|
|
|
const [serverAddress, setServerAddress] = useLocalStorage<String>('serverBaseURL', '');
|
2021-09-05 01:25:37 +04:30
|
|
|
const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true);
|
2021-09-18 20:59:23 +04:30
|
|
|
const [useCache, setUseCache] = useLocalStorage<boolean>('useCache', true);
|
2021-03-07 22:25:29 +03:30
|
|
|
const [dialogOpen, setDialogOpen] = useState(false);
|
|
|
|
|
const [dialogValue, setDialogValue] = useState(serverAddress);
|
|
|
|
|
|
2022-04-02 01:34:10 +01:00
|
|
|
const [dialogOpenItemWidth, setDialogOpenItemWidth] = useState(false);
|
2022-04-10 07:30:07 +01:00
|
|
|
const [ItemWidth, setItemWidth] = useLocalStorage<number>('ItemWidth', 300);
|
2022-04-02 01:34:10 +01:00
|
|
|
const [DialogItemWidth, setDialogItemWidth] = useState(ItemWidth);
|
|
|
|
|
|
2021-03-07 22:25:29 +03:30
|
|
|
const handleDialogOpen = () => {
|
|
|
|
|
setDialogValue(serverAddress);
|
|
|
|
|
setDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogCancel = () => {
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogSubmit = () => {
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
setServerAddress(dialogValue);
|
|
|
|
|
};
|
2021-02-20 01:23:52 +03:30
|
|
|
|
2022-04-02 01:34:10 +01:00
|
|
|
const handleDialogOpenItemWidth = () => {
|
|
|
|
|
setDialogItemWidth(ItemWidth);
|
|
|
|
|
setDialogOpenItemWidth(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogCancelItemWidth = () => {
|
|
|
|
|
setDialogOpenItemWidth(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogSubmitItemWidth = () => {
|
|
|
|
|
setDialogOpenItemWidth(false);
|
|
|
|
|
setItemWidth(DialogItemWidth);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogResetItemWidth = () => {
|
|
|
|
|
setDialogOpenItemWidth(false);
|
|
|
|
|
setItemWidth(300);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChange = (event: Event, newValue: number | number[]) => {
|
|
|
|
|
setDialogItemWidth(newValue as number);
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-20 01:23:52 +03:30
|
|
|
return (
|
2021-03-07 22:25:29 +03:30
|
|
|
<>
|
2021-11-15 19:58:05 +03:30
|
|
|
<List sx={{ padding: 0 }}>
|
2022-02-21 01:10:33 +03:30
|
|
|
<ListItemLink to="/settings/categories">
|
2021-02-20 01:23:52 +03:30
|
|
|
<ListItemIcon>
|
2021-05-23 15:28:46 +04:30
|
|
|
<ListAltIcon />
|
2021-02-20 01:23:52 +03:30
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('category.title.categories')} />
|
2021-02-20 01:23:52 +03:30
|
|
|
</ListItemLink>
|
2023-01-06 17:34:16 +01:00
|
|
|
<ListItemLink to="/settings/defaultReaderSettings">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<AutoStoriesIcon />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('reader.settings.title.default_reader_settings')} />
|
2023-01-06 17:34:16 +01:00
|
|
|
</ListItemLink>
|
2022-02-21 01:10:33 +03:30
|
|
|
<ListItemLink to="/settings/backup">
|
2021-04-10 00:44:13 +04:30
|
|
|
<ListItemIcon>
|
2021-05-23 15:28:46 +04:30
|
|
|
<BackupIcon />
|
2021-04-10 00:44:13 +04:30
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('settings.backup.title')} />
|
2021-04-10 00:44:13 +04:30
|
|
|
</ListItemLink>
|
2021-02-20 02:57:52 +03:30
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<Brightness6Icon />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('settings.label.dark_theme')} />
|
2021-02-20 02:57:52 +03:30
|
|
|
<ListItemSecondaryAction>
|
2023-02-08 18:19:26 +01:00
|
|
|
<Switch edge="end" checked={darkTheme} onChange={() => setDarkTheme(!darkTheme)} />
|
2021-02-20 02:57:52 +03:30
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
2023-03-04 22:21:24 +05:30
|
|
|
<SearchSettings />
|
2022-04-02 01:34:10 +01:00
|
|
|
<ListItemButton>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<ViewModuleIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText
|
2023-03-23 13:59:32 +01:00
|
|
|
primary={t('settings.label.manga_item_width')}
|
2022-04-02 01:34:10 +01:00
|
|
|
secondary={`px:${ItemWidth}`}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
handleDialogOpenItemWidth();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</ListItemButton>
|
2021-09-03 04:32:59 +04:30
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<FavoriteIcon />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.label.show_nsfw')}
|
|
|
|
|
secondary={t('settings.label.show_nsfw_description')}
|
|
|
|
|
/>
|
2021-09-03 04:32:59 +04:30
|
|
|
<ListItemSecondaryAction>
|
2023-02-08 18:19:26 +01:00
|
|
|
<Switch edge="end" checked={showNsfw} onChange={() => setShowNsfw(!showNsfw)} />
|
2021-09-18 20:59:23 +04:30
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<CachedIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText
|
2023-03-23 13:59:32 +01:00
|
|
|
primary={t('settings.label.image_cache')}
|
|
|
|
|
secondary={t('settings.label.image_cache_description')}
|
2021-09-18 20:59:23 +04:30
|
|
|
/>
|
|
|
|
|
<ListItemSecondaryAction>
|
2023-02-08 18:19:26 +01:00
|
|
|
<Switch edge="end" checked={useCache} onChange={() => setUseCache(!useCache)} />
|
2021-09-03 04:32:59 +04:30
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
2023-03-25 19:34:05 +01:00
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<LanguageIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('global.language.label.language')} />
|
|
|
|
|
<ListItemSecondaryAction>
|
|
|
|
|
<Select
|
|
|
|
|
MenuProps={{ PaperProps: { style: { maxHeight: 150 } } }}
|
|
|
|
|
value={i18n.language}
|
|
|
|
|
onChange={({ target: { value: language } }) => i18n.changeLanguage(language)}
|
|
|
|
|
>
|
|
|
|
|
{Object.keys(i18n.services.resourceStore.data).map((language) => (
|
|
|
|
|
<MenuItem key={language} value={language}>
|
|
|
|
|
{langCodeToName(language)}
|
|
|
|
|
</MenuItem>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
2021-03-07 22:25:29 +03:30
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<DnsIcon />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('settings.about.label.server_address')} secondary={serverAddress} />
|
2021-03-07 22:25:29 +03:30
|
|
|
<ListItemSecondaryAction>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
handleDialogOpen();
|
|
|
|
|
}}
|
2021-09-09 17:51:22 +04:30
|
|
|
size="large"
|
2021-03-07 22:25:29 +03:30
|
|
|
>
|
|
|
|
|
<EditIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
2022-02-21 01:10:33 +03:30
|
|
|
<ListItemLink to="/settings/about">
|
2021-05-25 21:06:27 +04:30
|
|
|
<ListItemIcon>
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText primary={t('settings.about.title')} />
|
2021-05-25 21:06:27 +04:30
|
|
|
</ListItemLink>
|
2021-02-20 01:23:52 +03:30
|
|
|
</List>
|
2021-03-07 22:25:29 +03:30
|
|
|
|
|
|
|
|
<Dialog open={dialogOpen} onClose={handleDialogCancel}>
|
|
|
|
|
<DialogContent>
|
2023-03-23 13:59:32 +01:00
|
|
|
<DialogContentText>{t('settings.server_address.dialog.label.enter_address')}</DialogContentText>
|
2021-03-07 22:25:29 +03:30
|
|
|
<TextField
|
|
|
|
|
autoFocus
|
|
|
|
|
margin="dense"
|
|
|
|
|
id="name"
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('settings.about.label.server_address')}
|
2021-03-07 22:25:29 +03:30
|
|
|
type="text"
|
|
|
|
|
fullWidth
|
|
|
|
|
value={dialogValue}
|
2021-10-06 21:33:16 +03:30
|
|
|
placeholder="http://127.0.0.1:4567"
|
2021-03-07 22:25:29 +03:30
|
|
|
onChange={(e) => setDialogValue(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<Button onClick={handleDialogCancel} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.cancel')}
|
2021-03-07 22:25:29 +03:30
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleDialogSubmit} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.set')}
|
2021-03-07 22:25:29 +03:30
|
|
|
</Button>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
2022-04-02 01:34:10 +01:00
|
|
|
|
|
|
|
|
<Dialog open={dialogOpenItemWidth} onClose={handleDialogCancelItemWidth}>
|
2023-03-23 13:59:32 +01:00
|
|
|
<DialogTitle>{t('settings.label.manga_item_width')}</DialogTitle>
|
2022-04-02 01:34:10 +01:00
|
|
|
<DialogContent
|
|
|
|
|
sx={{
|
|
|
|
|
width: '98%',
|
|
|
|
|
margin: 'auto',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TextField
|
|
|
|
|
sx={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
margin: 'auto',
|
|
|
|
|
}}
|
|
|
|
|
autoFocus
|
|
|
|
|
value={DialogItemWidth}
|
|
|
|
|
type="number"
|
|
|
|
|
onChange={(e) => setDialogItemWidth(parseInt(e.target.value, 10))}
|
|
|
|
|
/>
|
|
|
|
|
<Slider
|
|
|
|
|
aria-label="Manga Item width"
|
|
|
|
|
defaultValue={300}
|
|
|
|
|
value={DialogItemWidth}
|
|
|
|
|
step={10}
|
|
|
|
|
min={100}
|
|
|
|
|
max={1000}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<Button onClick={handleDialogResetItemWidth} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.reset_to_default')}
|
2022-04-02 01:34:10 +01:00
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleDialogCancelItemWidth} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.cancel')}
|
2022-04-02 01:34:10 +01:00
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleDialogSubmitItemWidth} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.ok')}
|
2022-04-02 01:34:10 +01:00
|
|
|
</Button>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
2021-03-07 22:25:29 +03:30
|
|
|
</>
|
2021-02-20 01:23:52 +03:30
|
|
|
);
|
|
|
|
|
}
|