Files
suwayomi-material-you-webui/src/modules/settings/screens/Settings.tsx

133 lines
5.5 KiB
TypeScript
Raw Normal View History

/*
* 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-02-20 01:23:52 +03:30
2025-01-21 20:34:17 +01:00
import { useLayoutEffect } from 'react';
import AutoStoriesIcon from '@mui/icons-material/AutoStories';
2021-09-09 17:51:22 +04:30
import List from '@mui/material/List';
import BackupIcon from '@mui/icons-material/Backup';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import ListItemButton from '@mui/material/ListItemButton';
import { useTranslation } from 'react-i18next';
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
import GetAppOutlinedIcon from '@mui/icons-material/GetAppOutlined';
import DnsIcon from '@mui/icons-material/Dns';
import WebIcon from '@mui/icons-material/Web';
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
2024-01-15 23:48:11 +01:00
import ExploreOutlinedIcon from '@mui/icons-material/ExploreOutlined';
import DevicesIcon from '@mui/icons-material/Devices';
2024-02-16 19:55:54 +01:00
import SyncIcon from '@mui/icons-material/Sync';
import PaletteIcon from '@mui/icons-material/Palette';
2024-10-05 16:09:34 +02:00
import { ListItemLink } from '@/modules/core/components/ListItemLink.tsx';
import { requestManager } from '@/lib/requests/RequestManager.ts';
2024-10-05 23:22:42 +02:00
import { makeToast } from '@/modules/core/utils/Toast.ts';
2024-12-11 20:10:59 +01:00
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
2024-12-20 17:24:40 +01:00
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
2025-01-21 20:34:17 +01:00
import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
2021-02-20 01:23:52 +03:30
2023-10-28 00:32:02 +02:00
export function Settings() {
const { t } = useTranslation();
2025-01-21 20:34:17 +01:00
const { setTitle, setAction } = useNavBarContext();
useLayoutEffect(() => {
setTitle(t('settings.title'));
setAction(null);
return () => {
setTitle('');
setAction(null);
};
}, [t]);
2021-03-09 16:44:09 +03:30
const [triggerClearServerCache, { loading: isClearingServerCache }] = requestManager.useClearServerCache();
const clearServerCache = async () => {
try {
await triggerClearServerCache();
makeToast(t('settings.clear_cache.label.success'), 'success');
} catch (e) {
2024-12-20 17:24:40 +01:00
makeToast(t('settings.clear_cache.label.failure'), 'error', getErrorMessage(e));
}
};
2021-02-20 01:23:52 +03:30
return (
<List sx={{ padding: 0 }}>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.appearance.path}>
<ListItemIcon>
<PaletteIcon />
</ListItemIcon>
<ListItemText primary={t('settings.appearance.title')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.reader.path}>
<ListItemIcon>
<AutoStoriesIcon />
</ListItemIcon>
<ListItemText primary={t('reader.settings.title.reader_settings')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.library.path}>
<ListItemIcon>
<CollectionsOutlinedBookmarkIcon />
</ListItemIcon>
<ListItemText primary={t('library.title')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.download.path}>
<ListItemIcon>
<GetAppOutlinedIcon />
</ListItemIcon>
<ListItemText primary={t('download.title.download')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.tracking.path}>
2024-02-16 19:55:54 +01:00
<ListItemIcon>
<SyncIcon />
</ListItemIcon>
<ListItemText primary={t('tracking.title')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.backup.path}>
<ListItemIcon>
<BackupIcon />
</ListItemIcon>
<ListItemText primary={t('settings.backup.title')} />
</ListItemLink>
<ListItemButton disabled={isClearingServerCache} onClick={clearServerCache}>
<ListItemIcon>
<DeleteForeverIcon />
</ListItemIcon>
<ListItemText
primary={t('settings.clear_cache.label.title')}
secondary={t('settings.clear_cache.label.description')}
/>
</ListItemButton>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.browse.path}>
2024-01-15 23:48:11 +01:00
<ListItemIcon>
<ExploreOutlinedIcon />
</ListItemIcon>
<ListItemText primary={t('global.label.browse')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.device.path}>
<ListItemIcon>
<DevicesIcon />
</ListItemIcon>
<ListItemText primary={t('settings.device.title.device')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.webui.path}>
<ListItemIcon>
<WebIcon />
</ListItemIcon>
<ListItemText primary={t('settings.webui.title.webui')} />
</ListItemLink>
2024-12-11 20:10:59 +01:00
<ListItemLink to={AppRoutes.settings.childRoutes.server.path}>
<ListItemIcon>
<DnsIcon />
</ListItemIcon>
<ListItemText primary={t('settings.server.title.server')} />
</ListItemLink>
</List>
2021-02-20 01:23:52 +03:30
);
}