|
| 1 | +import React, {useState} from "react"; |
| 2 | +import {useSelector} from "react-redux"; |
| 3 | +import Dialog from '@material-ui/core/Dialog'; |
| 4 | +import DialogActions from '@material-ui/core/DialogActions'; |
| 5 | +import DialogContent from '@material-ui/core/DialogContent'; |
| 6 | +import DialogContentText from '@material-ui/core/DialogContentText'; |
| 7 | +import DialogTitle from '@material-ui/core/DialogTitle'; |
| 8 | +import Button from "@material-ui/core/Button"; |
| 9 | + |
| 10 | +const UpdateDialog = ({downloadUrl, infoUrl, newVersion}) => { |
| 11 | + |
| 12 | + const language = useSelector(state => state.MainReducer.languages[state.MainReducer.languageIndex]); |
| 13 | + const [open, setOpen] = useState(true); |
| 14 | + |
| 15 | + /** |
| 16 | + * Close the UpdateDialog instance |
| 17 | + */ |
| 18 | + const handleClose = () => { |
| 19 | + setOpen(false); |
| 20 | + }; |
| 21 | + |
| 22 | + /** |
| 23 | + * Open the information page |
| 24 | + */ |
| 25 | + const openInformation = () => { |
| 26 | + window.open(infoUrl, '_blank'); |
| 27 | + }; |
| 28 | + |
| 29 | + /** |
| 30 | + * Open the download page |
| 31 | + */ |
| 32 | + const openDownload = () => { |
| 33 | + window.open(downloadUrl, '_blank'); |
| 34 | + handleClose(); |
| 35 | + }; |
| 36 | + |
| 37 | + return ( |
| 38 | + <Dialog |
| 39 | + open={open} |
| 40 | + onClose={handleClose} |
| 41 | + aria-labelledby="alert-dialog-title" |
| 42 | + aria-describedby="alert-dialog-description" |
| 43 | + > |
| 44 | + <DialogTitle id="alert-dialog-title">{language.updateAvailable}</DialogTitle> |
| 45 | + <DialogContent> |
| 46 | + <DialogContentText id="alert-dialog-description"> |
| 47 | + {language.newVersion.replace("{x}", newVersion)} |
| 48 | + </DialogContentText> |
| 49 | + </DialogContent> |
| 50 | + <DialogActions> |
| 51 | + <Button onClick={handleClose}> |
| 52 | + {language.cancel} |
| 53 | + </Button> |
| 54 | + <Button onClick={() => openInformation()} color="primary"> |
| 55 | + {language.information} |
| 56 | + </Button> |
| 57 | + <Button onClick={openDownload} color="primary" autoFocus> |
| 58 | + {language.download} |
| 59 | + </Button> |
| 60 | + </DialogActions> |
| 61 | + </Dialog> |
| 62 | + ); |
| 63 | +}; |
| 64 | + |
| 65 | +export default UpdateDialog; |
0 commit comments