-
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.
* Move "Server Address" setting to server settings * Rename "ServerDirSetting" to "TextSetting" * Use "TextSetting" for server address * Reset value when closing the dialog * Support passwords in "TextSetting" * Add server settings
- Loading branch information
Showing
11 changed files
with
612 additions
and
295 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (C) Contributors to the Suwayomi project | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. | ||
*/ | ||
|
||
import { Button, Dialog, DialogTitle, InputAdornment, ListItemText } from '@mui/material'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import TextField from '@mui/material/TextField'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import ListItemButton from '@mui/material/ListItemButton'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import DialogContentText from '@mui/material/DialogContentText'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import { Visibility, VisibilityOff } from '@mui/icons-material'; | ||
|
||
export const TextSetting = ({ | ||
settingName, | ||
dialogDescription, | ||
value, | ||
handleChange, | ||
isPassword = false, | ||
placeholder = '', | ||
}: { | ||
settingName: string; | ||
dialogDescription?: string; | ||
value?: string; | ||
handleChange: (value: string) => void; | ||
isPassword?: boolean; | ||
placeholder?: string; | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const [isDialogOpen, setIsDialogOpen] = useState(false); | ||
const [dialogValue, setDialogValue] = useState(value ?? ''); | ||
const [showPassword, setShowPassword] = useState(false); | ||
|
||
const handleClickShowPassword = () => setShowPassword((show) => !show); | ||
|
||
useEffect(() => { | ||
if (!value) { | ||
return; | ||
} | ||
|
||
setDialogValue(value); | ||
}, [value]); | ||
|
||
const closeDialog = (resetValue: boolean = true) => { | ||
if (resetValue) { | ||
setDialogValue(value ?? ''); | ||
} | ||
|
||
setShowPassword(false); | ||
setIsDialogOpen(false); | ||
}; | ||
|
||
const updateSetting = () => { | ||
closeDialog(false); | ||
handleChange(dialogValue); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ListItemButton onClick={() => setIsDialogOpen(true)}> | ||
<ListItemText | ||
primary={settingName} | ||
secondary={isPassword ? value?.replace(/./g, '*') : value ?? t('global.label.loading')} | ||
secondaryTypographyProps={{ style: { display: 'flex', flexDirection: 'column' } }} | ||
/> | ||
</ListItemButton> | ||
|
||
<Dialog open={isDialogOpen} onClose={() => closeDialog()} fullWidth> | ||
<DialogContent> | ||
<DialogTitle sx={{ paddingLeft: 0 }}>{settingName}</DialogTitle> | ||
{!!dialogDescription && ( | ||
<DialogContentText sx={{ paddingBottom: '10px' }}>{dialogDescription}</DialogContentText> | ||
)} | ||
<TextField | ||
sx={{ | ||
width: '100%', | ||
margin: 'auto', | ||
}} | ||
autoFocus | ||
placeholder={placeholder} | ||
value={dialogValue} | ||
type={isPassword && !showPassword ? 'password' : 'text'} | ||
onChange={(e) => setDialogValue(e.target.value)} | ||
InputProps={{ | ||
endAdornment: isPassword ? ( | ||
<InputAdornment position="end"> | ||
<IconButton | ||
aria-label="toggle password visibility" | ||
onClick={handleClickShowPassword} | ||
edge="end" | ||
> | ||
{showPassword ? <VisibilityOff /> : <Visibility />} | ||
</IconButton> | ||
</InputAdornment> | ||
) : null, | ||
}} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => closeDialog()} color="primary"> | ||
{t('global.button.cancel')} | ||
</Button> | ||
<Button onClick={() => updateSetting()} color="primary"> | ||
{t('global.button.ok')} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -455,5 +455,8 @@ export const SERVER_SETTINGS = gql` | |
backupTime | ||
backupInterval | ||
backupTTL | ||
# local source | ||
localSourcePath | ||
} | ||
`; |
Oops, something went wrong.