1
1
import React from 'react' ;
2
2
import Container from '../container/container' ;
3
+ import testLocalStorage from '../../utilities/test-local-storage' ;
3
4
4
5
const version = '1' ;
6
+ const localStorageIsEnabled = testLocalStorage ( ) !== false ;
5
7
6
8
export default class NotificationBar extends React . Component {
7
9
render ( ) {
@@ -15,10 +17,12 @@ export default class NotificationBar extends React.Component {
15
17
</ p >
16
18
< p >
17
19
Buy the brand-new webpack stickers at < a href = "http://www.unixstickers.com/tag/webpack" > Unixstickers!</ a >
18
-
19
- < i
20
- className = "notification-bar__close icon-cross"
21
- onClick = { this . _close . bind ( this ) } />
20
+ { localStorageIsEnabled ?
21
+ < i
22
+ className = "notification-bar__close icon-cross"
23
+ onClick = { this . _close . bind ( this ) } /> :
24
+ null
25
+ }
22
26
</ p >
23
27
</ Container >
24
28
</ div >
@@ -31,7 +35,9 @@ export default class NotificationBar extends React.Component {
31
35
* @param {object } e - Click event
32
36
*/
33
37
_close ( e ) {
34
- localStorage . setItem ( 'notification-dismissed' , version ) ;
38
+ if ( localStorageIsEnabled ) {
39
+ localStorage . setItem ( 'notification-dismissed' , version ) ;
40
+ }
35
41
this . forceUpdate ( ) ;
36
42
}
37
43
@@ -41,7 +47,7 @@ export default class NotificationBar extends React.Component {
41
47
* @return {boolean } - Whether or not the current message was dismissed
42
48
*/
43
49
get _dismissed ( ) {
44
- if ( typeof window !== 'undefined' ) {
50
+ if ( localStorageIsEnabled ) {
45
51
return localStorage . getItem ( 'notification-dismissed' ) === version ;
46
52
47
53
} else return false ;
0 commit comments