-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated the settings page design (#215)
- Loading branch information
1 parent
b666cd2
commit 32e5ea9
Showing
2 changed files
with
8 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,15 @@ | ||
import { ReactElement, useState, useContext } from 'react' | ||
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles' | ||
import { TextField, Typography, Button } from '@material-ui/core' | ||
import { ReactElement, useContext } from 'react' | ||
import { Context as SettingsContext } from '../../providers/Settings' | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
item: { | ||
margin: 0, | ||
marginTop: theme.spacing(4), | ||
}, | ||
}), | ||
) | ||
import ExpandableList from '../../components/ExpandableList' | ||
import ExpandableListItemInput from '../../components/ExpandableListItemInput' | ||
|
||
export default function Settings(): ReactElement { | ||
const classes = useStyles() | ||
const { apiUrl, apiDebugUrl, setApiUrl, setDebugApiUrl } = useContext(SettingsContext) | ||
const [host, setHost] = useState(apiUrl) | ||
const [debugHost, setDebugHost] = useState(apiDebugUrl) | ||
|
||
const submit = () => { | ||
if (host !== apiUrl) setApiUrl(host) | ||
|
||
if (debugHost !== apiDebugUrl) setDebugApiUrl(debugHost) | ||
} | ||
|
||
const touched = host !== apiUrl || debugHost !== apiDebugUrl | ||
|
||
return ( | ||
<> | ||
<Typography variant="h4" gutterBottom> | ||
Settings | ||
</Typography> | ||
<TextField | ||
label="API Endpoint" | ||
className={classes.item} | ||
placeholder="ex: 127.0.0.0.1:1633" | ||
fullWidth | ||
defaultValue={apiUrl} | ||
margin="normal" | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
onChange={e => { | ||
setHost(e.target.value) | ||
}} | ||
/> | ||
<TextField | ||
label="Debug API Endpoint" | ||
className={classes.item} | ||
placeholder="ex: 127.0.0.0.1:1635" | ||
fullWidth | ||
defaultValue={apiDebugUrl} | ||
onChange={e => { | ||
setDebugHost(e.target.value) | ||
}} | ||
margin="normal" | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
/> | ||
{touched && ( | ||
<Button variant="outlined" color="primary" className={classes.item} onClick={submit}> | ||
Save | ||
</Button> | ||
)} | ||
</> | ||
<ExpandableList label="API Settings" defaultOpen> | ||
<ExpandableListItemInput label="Bee API" value={apiUrl} onConfirm={setApiUrl} /> | ||
<ExpandableListItemInput label="Bee Debug API" value={apiDebugUrl} onConfirm={setDebugApiUrl} /> | ||
</ExpandableList> | ||
) | ||
} |