tachiyomi-extensions-inspector/webUI/react/src/screens/Settings.tsx

122 lines
4.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-19 22:53:52 +01:00
* 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 14:14:09 +01:00
import React, { useContext, useEffect, useState } from 'react';
2021-02-19 22:53:52 +01:00
import List from '@material-ui/core/List';
import InboxIcon from '@material-ui/icons/Inbox';
2021-02-20 00:27:52 +01:00
import Brightness6Icon from '@material-ui/icons/Brightness6';
import DnsIcon from '@material-ui/icons/Dns';
import EditIcon from '@material-ui/icons/Edit';
import {
Button, Dialog, DialogActions, DialogContent,
DialogContentText, IconButton, ListItemSecondaryAction, Switch, TextField,
ListItemIcon, ListItemText,
} from '@material-ui/core';
2021-04-09 22:14:13 +02:00
import ListItem from '@material-ui/core/ListItem';
2021-03-08 18:34:42 +01:00
import NavbarContext from '../context/NavbarContext';
2021-02-20 00:27:52 +01:00
import DarkTheme from '../context/DarkTheme';
import useLocalStorage from '../util/useLocalStorage';
2021-04-09 22:14:13 +02:00
import ListItemLink from '../util/ListItemLink';
2021-02-19 22:53:52 +01:00
export default function Settings() {
2021-03-09 14:14:09 +01:00
const { setTitle, setAction } = useContext(NavbarContext);
useEffect(() => { setTitle('Settings'); setAction(<></>); }, []);
2021-02-20 00:27:52 +01:00
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
const [serverAddress, setServerAddress] = useLocalStorage<String>('serverBaseURL', '');
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-19 22:53:52 +01:00
return (
<>
2021-03-09 14:14:09 +01:00
<List style={{ padding: 0 }}>
2021-02-19 22:53:52 +01:00
<ListItemLink href="/settings/categories">
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText primary="Categories" />
</ListItemLink>
2021-04-09 22:14:13 +02:00
<ListItemLink href="/settings/backup">
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText primary="Backup" />
</ListItemLink>
2021-02-20 00:27:52 +01:00
<ListItem>
<ListItemIcon>
<Brightness6Icon />
</ListItemIcon>
<ListItemText primary="Dark Theme" />
<ListItemSecondaryAction>
<Switch
edge="end"
checked={darkTheme}
onChange={() => setDarkTheme(!darkTheme)}
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<DnsIcon />
</ListItemIcon>
<ListItemText primary="Server Address" secondary={serverAddress} />
<ListItemSecondaryAction>
<IconButton
onClick={() => {
handleDialogOpen();
}}
>
<EditIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
2021-02-19 22:53:52 +01:00
</List>
<Dialog open={dialogOpen} onClose={handleDialogCancel}>
<DialogContent>
<DialogContentText>
Enter new category name.
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="name"
label="Category Name"
type="text"
fullWidth
value={dialogValue}
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-19 22:53:52 +01:00
);
}