1
- import React from 'react' ;
1
+ import { default as React , Component } from 'react' ;
2
2
import request from 'superagent' ;
3
3
import { DefaultSession as RethinkSession } from 'react-rethinkdb' ;
4
4
import { ChatBox } from './ChatBox' ;
@@ -11,19 +11,24 @@ const apiServer = {
11
11
port : webPort
12
12
}
13
13
14
- export const AuthWrapper = React . createClass ( {
15
- getInitialState ( ) {
16
- return {
14
+ export class AuthWrapper extends Component {
15
+ constructor ( props ) {
16
+ super ( props ) ;
17
+ this . state = {
17
18
userId : window . localStorage . getItem ( 'userId' ) ,
18
19
error : false ,
19
20
} ;
20
- } ,
21
+ this . handleButton = this . handleButton . bind ( this ) ;
22
+ this . handleLogout = this . handleLogout . bind ( this ) ;
23
+ this . renderLoggedIn = this . renderLoggedIn . bind ( this ) ;
24
+ this . renderLoggedOut = this . renderLoggedOut . bind ( this ) ;
25
+ }
21
26
22
27
componentWillMount ( ) {
23
28
if ( this . state . userId ) {
24
29
this . connect ( ) ;
25
30
}
26
- } ,
31
+ }
27
32
28
33
connect ( ) {
29
34
const userId = window . localStorage . getItem ( 'userId' ) ;
@@ -39,7 +44,7 @@ export const AuthWrapper = React.createClass({
39
44
secure : secure ,
40
45
db : 'react_example_chat' ,
41
46
} ) ;
42
- } ,
47
+ }
43
48
44
49
handleButton ( action , event ) {
45
50
event . preventDefault ( ) ;
@@ -64,14 +69,14 @@ export const AuthWrapper = React.createClass({
64
69
this . setState ( { userId} ) ;
65
70
}
66
71
} ) ;
67
- } ,
72
+ }
68
73
69
74
handleLogout ( ) {
70
75
RethinkSession . close ( ) ;
71
76
this . setState ( { userId : null } ) ;
72
77
window . localStorage . removeItem ( 'userId' ) ;
73
78
window . localStorage . removeItem ( 'authToken' ) ;
74
- } ,
79
+ }
75
80
76
81
renderLoggedIn ( ) {
77
82
return (
@@ -86,7 +91,7 @@ export const AuthWrapper = React.createClass({
86
91
</ div >
87
92
</ div >
88
93
) ;
89
- } ,
94
+ }
90
95
91
96
renderLoggedOut ( ) {
92
97
return (
@@ -102,13 +107,13 @@ export const AuthWrapper = React.createClass({
102
107
</ button >
103
108
</ div >
104
109
) ;
105
- } ,
110
+ }
106
111
107
112
render ( ) {
108
113
if ( this . state . userId ) {
109
114
return this . renderLoggedIn ( ) ;
110
115
} else {
111
116
return this . renderLoggedOut ( ) ;
112
117
}
113
- } ,
114
- } ) ;
118
+ }
119
+ }
0 commit comments