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

174 lines
7.0 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-03-09 16:44:09 +03:30
import React, { useContext, useEffect, useState } from 'react';
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';
2021-10-30 16:10:34 +03:30
import NavbarContext from '../components/context/NavbarContext';
import DarkTheme from '../components/context/DarkTheme';
import useLocalStorage from '../util/useLocalStorage';
import ListItemLink from '../components/util/ListItemLink';
2021-02-20 01:23:52 +03:30
export default function Settings() {
2021-03-09 16:44:09 +03:30
const { setTitle, setAction } = useContext(NavbarContext);
useEffect(() => { setTitle('Settings'); setAction(<></>); }, []);
2021-02-20 02:57:52 +03:30
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
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);
const [dialogOpen, setDialogOpen] = useState(false);
const [dialogValue, setDialogValue] = useState(serverAddress);
const handleDialogOpen = () => {
setDialogValue(serverAddress);
setDialogOpen(true);
};
const handleDialogCancel = () => {
setDialogOpen(false);
};
const handleDialogSubmit = () => {
setDialogOpen(false);
setServerAddress(dialogValue);
};
2021-02-20 01:23:52 +03:30
return (
<>
<List style={{ padding: 0 }}>
2021-02-20 01:23:52 +03:30
<ListItemLink href="/settings/categories">
<ListItemIcon>
<ListAltIcon />
2021-02-20 01:23:52 +03:30
</ListItemIcon>
<ListItemText primary="Categories" />
</ListItemLink>
2021-04-10 00:44:13 +04:30
<ListItemLink href="/settings/backup">
<ListItemIcon>
<BackupIcon />
2021-04-10 00:44:13 +04:30
</ListItemIcon>
<ListItemText primary="Backup" />
</ListItemLink>
2021-02-20 02:57:52 +03:30
<ListItem>
<ListItemIcon>
<Brightness6Icon />
</ListItemIcon>
<ListItemText primary="Dark Theme" />
<ListItemSecondaryAction>
<Switch
edge="end"
checked={darkTheme}
onChange={() => setDarkTheme(!darkTheme)}
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<FavoriteIcon />
</ListItemIcon>
2021-09-18 20:59:23 +04:30
<ListItemText
primary="Show NSFW"
secondary="Hide NSFW extensions and sources"
/>
<ListItemSecondaryAction>
<Switch
edge="end"
checked={showNsfw}
onChange={() => setShowNsfw(!showNsfw)}
/>
2021-09-18 20:59:23 +04:30
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<CachedIcon />
</ListItemIcon>
<ListItemText
primary="Use image cache"
secondary="Disabling image cache makes images load faster if you have a slow disk,
but uses it much more internet traffic in turn"
/>
<ListItemSecondaryAction>
<Switch
edge="end"
checked={useCache}
onChange={() => setUseCache(!useCache)}
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<DnsIcon />
</ListItemIcon>
<ListItemText primary="Server Address" secondary={serverAddress} />
<ListItemSecondaryAction>
<IconButton
onClick={() => {
handleDialogOpen();
}}
2021-09-09 17:51:22 +04:30
size="large"
>
<EditIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
2021-05-25 21:06:27 +04:30
<ListItemLink href="/settings/about">
<ListItemIcon>
<InfoIcon />
</ListItemIcon>
<ListItemText primary="About" />
</ListItemLink>
2021-02-20 01:23:52 +03:30
</List>
<Dialog open={dialogOpen} onClose={handleDialogCancel}>
<DialogContent>
<DialogContentText>
2021-10-06 21:33:16 +03:30
Enter Server Address
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="name"
2021-10-06 21:33:16 +03:30
label="Server Address"
type="text"
fullWidth
value={dialogValue}
2021-10-06 21:33:16 +03:30
placeholder="http://127.0.0.1:4567"
onChange={(e) => setDialogValue(e.target.value)}
/>
</DialogContent>
<DialogActions>
<Button onClick={handleDialogCancel} color="primary">
Cancel
</Button>
<Button onClick={handleDialogSubmit} color="primary">
Set
</Button>
</DialogActions>
</Dialog>
</>
2021-02-20 01:23:52 +03:30
);
}