-
Notifications
You must be signed in to change notification settings - Fork 2
/
OfflineToast.jsx
48 lines (40 loc) 路 1.08 KB
/
OfflineToast.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { PureComponent } from "react";
import { bool } from "prop-types";
import classNames from "classnames";
import { FormattedMessage } from "react-intl";
import { toast, ToastContainer } from "react-toastify";
const message = () => (
<div>
<i className="fa fa-warning" /> <FormattedMessage id="app.offline" />
</div>
);
export default class OfflineToast extends PureComponent {
static propTypes = {
offline: bool
};
toastId = null;
static _showMessage(offline) {
const { BOTTOM_RIGHT } = toast.POSITION;
if (toast.isActive(this.toastId)) {
return;
}
return offline
? (this.toastId = toast(message, {
position: BOTTOM_RIGHT,
closeButton: false,
autoClose: false,
closeOnClick: false,
className: classNames("toast", { offline })
}))
: toast.dismiss();
}
componentDidMount() {
OfflineToast._showMessage(this.props.offline);
}
componentWillReceiveProps({ offline }) {
OfflineToast._showMessage(offline);
}
render() {
return <ToastContainer />;
}
}