2021-09-13 19:18:21 +04:30
|
|
|
/*
|
|
|
|
|
* 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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-09-13 19:18:21 +04:30
|
|
|
|
2023-08-14 21:43:06 +02:00
|
|
|
import { useState } from 'react';
|
2021-09-13 19:18:21 +04:30
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
|
|
|
|
import Dialog from '@mui/material/Dialog';
|
|
|
|
|
import DialogTitle from '@mui/material/DialogTitle';
|
|
|
|
|
import DialogContent from '@mui/material/DialogContent';
|
|
|
|
|
import DialogContentText from '@mui/material/DialogContentText';
|
|
|
|
|
import DialogActions from '@mui/material/DialogActions';
|
|
|
|
|
import TextField from '@mui/material/TextField';
|
|
|
|
|
import Button from '@mui/material/Button';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-06-04 21:13:07 +02:00
|
|
|
import { ListItemButton } from '@mui/material';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { EditTextPreferenceProps } from '@/typings';
|
2021-09-13 19:18:21 +04:30
|
|
|
|
|
|
|
|
export default function EditTextPreference(props: EditTextPreferenceProps) {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
const { title, summary, dialogTitle, dialogMessage, currentValue, updateValue } = props;
|
2021-09-13 19:18:21 +04:30
|
|
|
|
|
|
|
|
const [internalCurrentValue, setInternalCurrentValue] = useState<string>(currentValue);
|
|
|
|
|
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
|
|
|
|
|
|
|
|
|
|
const handleDialogCancel = () => {
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
|
|
|
|
|
// reset the dialog
|
|
|
|
|
setInternalCurrentValue(currentValue);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDialogSubmit = () => {
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
|
|
|
|
|
updateValue(internalCurrentValue);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-06-04 21:13:07 +02:00
|
|
|
<ListItemButton onClick={() => setDialogOpen(true)}>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ListItemText primary={title} secondary={summary} />
|
2023-06-04 21:13:07 +02:00
|
|
|
</ListItemButton>
|
2021-09-13 19:18:21 +04:30
|
|
|
<Dialog open={dialogOpen} onClose={handleDialogCancel}>
|
2023-02-06 10:06:33 +01:00
|
|
|
<DialogTitle>{dialogTitle}</DialogTitle>
|
2021-09-13 19:18:21 +04:30
|
|
|
<DialogContent>
|
2023-02-06 10:06:33 +01:00
|
|
|
<DialogContentText>{dialogMessage}</DialogContentText>
|
2021-09-13 19:18:21 +04:30
|
|
|
<TextField
|
|
|
|
|
autoFocus
|
|
|
|
|
margin="dense"
|
|
|
|
|
id="name"
|
|
|
|
|
type="text"
|
|
|
|
|
fullWidth
|
|
|
|
|
value={internalCurrentValue}
|
|
|
|
|
onChange={(e) => setInternalCurrentValue(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<Button onClick={handleDialogCancel} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.cancel')}
|
2021-09-13 19:18:21 +04:30
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleDialogSubmit} color="primary">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.ok')}
|
2021-09-13 19:18:21 +04:30
|
|
|
</Button>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|