-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathComponents_NotificationHandler_NotificationHandler.jsx.html
217 lines (184 loc) · 7.54 KB
/
Components_NotificationHandler_NotificationHandler.jsx.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Components/NotificationHandler/NotificationHandler.jsx</title>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="./build/entry.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="https://fonts.googleapis.com/css?family=Muli:100,400,700|Oswald:300|Inconsolata,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
</head>
<body>
<div id="stickyNavbarOverlay"></div>
<div class="top-navbar">
<div class="container">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<h1 class="navbar-item">Documentation</h1>
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
</nav>
</div>
</div>
<div class="container">
<div class="columns">
<div class="column is-3" id="sidebarNav">
<div class="sidebar">
<nav>
<h2><a href="index.html">Home</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#App">App</a></li><li><a href="global.html#TrackSelect">TrackSelect</a></li></ul></div><div class="category"><h2>Constants</h2><h3>Global</h3><ul><li><a href="global.html#DEFAULT_MOTS">DEFAULT_MOTS</a></li></ul></div><div class="category"><h2>Map</h2><h3>Classes</h3><ul><li><a href="MapComponent.html">MapComponent</a></li></ul></div><div class="category"><h2>NotificationHandler</h2><h3>Classes</h3><ul><li><a href="NotificationHandler.html">NotificationHandler</a></li></ul></div><div class="category"><h2>Props</h2><h3><a href="global.html">Global</a></h3></div><div class="category"><h2>RoutingMenu</h2><h3>Global</h3><ul><li><a href="global.html#RoutingMenu">RoutingMenu</a></li><li><a href="global.html#SearchField">SearchField</a></li><li><a href="global.html#SearchResults">SearchResults</a></li></ul></div><div class="category"><h2>Utils</h2><h3>Global</h3><ul><li><a href="global.html#findMotIcon">findMotIcon</a></li></ul></div>
</nav>
</div>
</div>
<div class="column is-9-desktop">
<div class="content" id="main-content-wrapper">
<header class="page-title">
<p>Source</p>
<h1>Components/NotificationHandler/NotificationHandler.jsx</h1>
</header>
<section>
<article>
<pre class="prettyprint source linenums"><code>import React from 'react';
import Snackbar from '@material-ui/core/Snackbar';
import { connect } from 'react-redux';
import Alert from '@material-ui/lab/Alert';
import PropTypes from 'prop-types';
import { showNotification } from '../../store/actions';
/**
* The notification handler props
* @typedef NotificationHandlerProps
* @type {props}
* @property {string} notificationMessage Obtained from the store, the message to be displayed. Can be any valid string.
* @property {string} notificationType Obtained from the store, the message type (error, success, info, etc...)
* @category Props
*/
/**
* Handles all application notification shown to the user
* @category NotificationHandler
*/
class NotificationHandler extends React.Component {
/**
* Default constructor. visibility is set to false by default. Controlled through state property "open"
* @param {...NotificationHandlerProps} props Props received so that the component can function properly.
* @category NotificationHandler
*/
constructor(props) {
super(props);
this.state = {
open: false,
};
}
/**
* If a new notification message is received, show it accordingly.
* @category NotificationHandler
*/
componentDidUpdate(prevProps) {
const { notificationMessage } = this.props;
if (
notificationMessage &&
notificationMessage !== prevProps.notificationMessage
) {
this.handleOpen();
}
}
/**
* Show the notification to the view.
* @category NotificationHandler
*/
handleOpen = () => {
this.setState({
open: true,
});
};
/**
* Hide the notification from the view.
* @category NotificationHandler
*/
handleClose = () => {
const { onShowNotification } = this.props;
this.setState({
open: false,
});
onShowNotification(null, 'error');
};
/**
* Render the notification to the dom.
* @category NotificationHandler
*/
render() {
const { notificationMessage, notificationType } = this.props;
const { open } = this.state;
return (
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={open}
autoHideDuration={6000}
onClose={this.handleClose}
>
<Alert
onClose={this.handleClose}
severity={notificationType}
elevation={6}
variant="filled"
>
{notificationMessage}
</Alert>
</Snackbar>
);
}
}
const mapDispatchToProps = dispatch => {
return {
onShowNotification: (notificationMessage, notificationType) =>
dispatch(showNotification(notificationMessage, notificationType)),
};
};
const mapStateToProps = state => {
return {
notificationMessage: state.MapReducer.notificationMessage,
notificationType: state.MapReducer.notificationType,
};
};
NotificationHandler.propTypes = {
onShowNotification: PropTypes.func.isRequired,
notificationMessage: PropTypes.string.isRequired,
notificationType: PropTypes.string.isRequired,
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(NotificationHandler);
</code></pre>
</article>
</section>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="content has-text-centered">
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri May 21 2021 15:30:36 GMT+0200 (Central European Summer Time)</p>
<p class="sidebar-created-by">
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
</p>
</div>
</footer>
<script src="scripts/app.min.js"></script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>