Skip to content

Commit aac9b79

Browse files
committed
* Make use of dialogs for displaying alerts
1 parent e7dfa00 commit aac9b79

File tree

4 files changed

+49
-59
lines changed

4 files changed

+49
-59
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, {useState} from "react";
2+
import DialogTitle from "@material-ui/core/DialogTitle";
3+
import DialogContent from "@material-ui/core/DialogContent";
4+
import DialogContentText from "@material-ui/core/DialogContentText";
5+
import DialogActions from "@material-ui/core/DialogActions";
6+
import Button from "@material-ui/core/Button";
7+
import Dialog from "@material-ui/core/Dialog";
8+
import {useSelector} from "react-redux";
9+
10+
const AlertDialog = ({title, content}) => {
11+
12+
const language = useSelector(state => state.MainReducer.languages[state.MainReducer.languageIndex]);
13+
const [open, setOpen] = useState(true);
14+
15+
/**
16+
* Close the AlertDialog instance
17+
*/
18+
const handleClose = () => {
19+
setOpen(false);
20+
};
21+
22+
return (
23+
<Dialog
24+
open={open}
25+
onClose={handleClose}
26+
aria-labelledby="alert-dialog-title"
27+
aria-describedby="alert-dialog-description"
28+
>
29+
<DialogTitle id="alert-dialog-title">{title}</DialogTitle>
30+
<DialogContent>
31+
<DialogContentText id="alert-dialog-description">
32+
{content}
33+
</DialogContentText>
34+
</DialogContent>
35+
<DialogActions>
36+
<Button onClick={handleClose} color="primary" autoFocus>
37+
{language.ok}
38+
</Button>
39+
</DialogActions>
40+
</Dialog>
41+
);
42+
};
43+
44+
export default AlertDialog;

src/components/AlertModal/index.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/routes/Home/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import Button from "@material-ui/core/Button";
1212
import Card from "@material-ui/core/Card";
1313
import {useHistory} from "react-router";
1414
import blank from "../../components/Theme/blank.png";
15-
import AlertModal from "../../components/AlertModal";
1615
import {Updater} from "../../utils/Updater";
1716
import UpdateDialog from "../../components/UpdateDialog";
17+
import AlertDialog from "../../components/AlertDialog";
1818

1919
const useStyles = makeStyles(theme => ({
2020
heroContent: {
@@ -104,7 +104,7 @@ const Home = () => {
104104
</div>
105105
<main className={classes.content}>
106106
{update && update.updateAvailable ? (<UpdateDialog downloadUrl={update.updateUrl} infoUrl={update.infoUrl} newVersion={update.version} />) : null}
107-
{errorMessage && errorMessage.length > 0 ? (<AlertModal title={language.errorTitle} content={errorMessage}/>) : null}
107+
{errorMessage && errorMessage.length > 0 ? (<AlertDialog title={language.errorTitle} content={errorMessage}/>) : null}
108108
<Container maxWidth={"lg"} className={classes.container}>
109109
<Grid container spacing={2}>
110110
<Grid item xs={12} md={6} lg={6}>

src/routes/Settings/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import MenuItem from "@material-ui/core/MenuItem";
2424
import Button from "@material-ui/core/Button";
2525
import RefreshIcon from "@material-ui/icons/Refresh";
2626
import {Updater} from "../../utils/Updater";
27-
import AlertModal from "../../components/AlertModal";
2827
import BackButton from "../../components/BackButton";
2928
import UpdateDialog from "../../components/UpdateDialog";
29+
import AlertDialog from "../../components/AlertDialog";
3030

3131
const useStyles = makeStyles(theme => ({
3232
content: {
@@ -146,9 +146,9 @@ const Settings = () => {
146146
<UpdateDialog downloadUrl={update.updateUrl} infoUrl={update.infoUrl}
147147
newVersion={update.version} />) : null}
148148
{update && !update.updateAvailable ? (
149-
<AlertModal title={language.noUpdatesTitle} content={language.noUpdatesMessage}/>) : null}
149+
<AlertDialog title={language.noUpdatesTitle} content={language.noUpdatesMessage}/>) : null}
150150
{errorMessage && errorMessage.length > 0 ? (
151-
<AlertModal title={language.errorTitle} content={errorMessage}/>) : null}
151+
<AlertDialog title={language.errorTitle} content={errorMessage}/>) : null}
152152
<Container maxWidth="lg" className={classes.container}>
153153
<Grid container spacing={2}>
154154
<Grid item xs={12} md={12} lg={12}>

0 commit comments

Comments
 (0)