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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-02-20 01:23:52 +03:30
|
|
|
|
2023-11-18 19:55:44 +01:00
|
|
|
import { useContext, useEffect, useMemo } 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 InfoIcon from '@mui/icons-material/Info';
|
|
|
|
|
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 FavoriteIcon from '@mui/icons-material/Favorite';
|
2023-11-18 19:55:44 +01:00
|
|
|
import { Link, MenuItem, Select } from '@mui/material';
|
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';
|
2023-04-22 13:03:51 +02:00
|
|
|
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
|
2023-11-04 14:40:43 +01:00
|
|
|
import GetAppOutlinedIcon from '@mui/icons-material/GetAppOutlined';
|
|
|
|
|
import ViewModuleIcon from '@mui/icons-material/ViewModule';
|
2023-11-18 19:55:44 +01:00
|
|
|
import DnsIcon from '@mui/icons-material/Dns';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { langCodeToName } from '@/util/language';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { useLocalStorage } from '@/util/useLocalStorage';
|
|
|
|
|
import { ListItemLink } from '@/components/util/ListItemLink';
|
|
|
|
|
import { DarkTheme } from '@/components/context/DarkTheme';
|
|
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
2023-11-04 14:40:43 +01:00
|
|
|
import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
|
2021-02-20 01:23:52 +03:30
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function Settings() {
|
2023-03-25 19:34:05 +01:00
|
|
|
const { t, i18n } = useTranslation();
|
2023-03-23 13:59:32 +01:00
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
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-03-28 23:14:03 +02:00
|
|
|
}, [t]);
|
2021-03-09 16:44:09 +03:30
|
|
|
|
2021-02-20 02:57:52 +03:30
|
|
|
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
|
2021-09-05 01:25:37 +04:30
|
|
|
const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true);
|
2021-03-07 22:25:29 +03:30
|
|
|
|
2023-11-04 14:40:43 +01:00
|
|
|
const DEFAULT_ITEM_WIDTH = 300;
|
|
|
|
|
const itemWidthIcon = useMemo(() => <ViewModuleIcon />, []);
|
|
|
|
|
const [itemWidth, setItemWidth] = useLocalStorage<number>('ItemWidth', DEFAULT_ITEM_WIDTH);
|
2022-04-02 01:34:10 +01:00
|
|
|
|
2021-02-20 01:23:52 +03:30
|
|
|
return (
|
2023-11-18 19:55:44 +01:00
|
|
|
<List sx={{ padding: 0 }}>
|
|
|
|
|
<ListItemLink to="/settings/categories">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<ListAltIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('category.title.categories')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItemLink to="/settings/defaultReaderSettings">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<AutoStoriesIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('reader.settings.title.default_reader_settings')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItemLink to="/settings/librarySettings">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<CollectionsOutlinedBookmarkIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('library.title')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItemLink to="/settings/downloadSettings">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<GetAppOutlinedIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('download.title')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItemLink to="/settings/backup">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<BackupIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('settings.backup.title')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<Brightness6Icon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('settings.label.dark_theme')} />
|
|
|
|
|
<ListItemSecondaryAction>
|
|
|
|
|
<Switch edge="end" checked={darkTheme} onChange={() => setDarkTheme(!darkTheme)} />
|
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
|
|
|
|
<NumberSetting
|
|
|
|
|
settingTitle={t('settings.label.manga_item_width')}
|
|
|
|
|
settingValue={`px:${itemWidth}`}
|
|
|
|
|
settingIcon={itemWidthIcon}
|
|
|
|
|
value={itemWidth}
|
|
|
|
|
defaultValue={DEFAULT_ITEM_WIDTH}
|
|
|
|
|
minValue={100}
|
|
|
|
|
maxValue={1000}
|
|
|
|
|
stepSize={10}
|
|
|
|
|
dialogTitle={t('settings.label.manga_item_width')}
|
|
|
|
|
valueUnit="px"
|
|
|
|
|
showSlider
|
|
|
|
|
handleUpdate={setItemWidth}
|
|
|
|
|
/>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<FavoriteIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.label.show_nsfw')}
|
|
|
|
|
secondary={t('settings.label.show_nsfw_description')}
|
2023-11-04 14:40:43 +01:00
|
|
|
/>
|
2023-11-18 19:55:44 +01:00
|
|
|
<ListItemSecondaryAction>
|
|
|
|
|
<Switch edge="end" checked={showNsfw} onChange={() => setShowNsfw(!showNsfw)} />
|
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
|
</ListItem>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<LanguageIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('global.language.label.language')}
|
|
|
|
|
secondary={
|
|
|
|
|
<>
|
|
|
|
|
<span>{t('settings.label.language_description')} </span>
|
|
|
|
|
<Link href="https://hosted.weblate.org/projects/suwayomi/tachidesk-webui">
|
|
|
|
|
{t('global.language.title.weblate')}
|
|
|
|
|
</Link>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<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>
|
|
|
|
|
<ListItemLink to="/settings/server">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<DnsIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('settings.server.title.server')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
<ListItemLink to="/settings/about">
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
</ListItemIcon>
|
|
|
|
|
<ListItemText primary={t('settings.about.title')} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
</List>
|
2021-02-20 01:23:52 +03:30
|
|
|
);
|
|
|
|
|
}
|