@@ -42,50 +42,68 @@ class MessageBoard extends Component {
42
42
nowTime : new Date ( ) ,
43
43
blockArr : [
44
44
< MessageBlock
45
+ key = { `message-left number ${ 0 } ` }
45
46
orderIn = { 0 }
46
47
textIn = "Go Ahead!"
47
48
emotionIn = "happy"
48
49
/> ,
49
50
< MessageBlock
51
+ key = { `message-left number ${ 1 } ` }
50
52
orderIn = { 1 }
51
53
textIn = "Let's Chat!"
52
54
emotionIn = "happy"
53
55
/>
54
56
] ,
55
57
} ;
58
+ this . visitorText = '' ;
59
+ this . visitorName = '' ;
60
+ this . blockCreate = this . blockCreate . bind ( this ) ;
56
61
}
57
62
componentDidMount ( ) {
58
63
this . startTick = setInterval ( ( ) => {
59
64
this . setState ( { nowTime : new Date ( ) } ) ;
60
65
} , 1000 ) ;
61
66
}
62
67
componentWillUnmount ( ) { clearInterval ( this . startTick ) ; }
68
+ blockCreate ( emotionStr ) {
69
+ return ( ( ) => {
70
+ this . visitorText = this . visitorText . trim ( ) ;
71
+ this . visitorName = this . visitorName . trim ( ) ;
72
+ if ( this . visitorText === '' ) return ;
73
+ if ( this . visitorName === '' ) this . visitorName = '(Anonymous)' ;
74
+ const { blockArr, nowTime } = this . state ;
75
+ blockArr . push (
76
+ < MessageBlock
77
+ key = { `message-left number ${ blockArr . length } ` }
78
+ orderIn = { blockArr . length }
79
+ textIn = { this . visitorText }
80
+ visitorIn = { this . visitorName }
81
+ timeIn = { nowTime . toString ( ) }
82
+ emotionIn = { emotionStr }
83
+ />
84
+ ) ;
85
+ this . setState ( { nowTime : new Date ( ) } ) ;
86
+ } ) ;
87
+ }
63
88
render ( ) {
64
89
return (
65
90
< div className = "MessageBoard" >
66
91
< div className = "blockArr" > { this . state . blockArr } </ div >
67
92
< textarea placeholder = "Text here to leave a message..." onKeyUp = { e => {
68
- this . visitorName = e . target . value ;
93
+ this . visitorText = e . target . value ;
69
94
} } />
70
95
< input placeholder = "Nickname, please." onKeyUp = { e => {
71
- this . visitorText = e . target . value ;
96
+ this . visitorName = e . target . value ;
72
97
} } />
73
- < img src = "./dist/png_512/1f603.png" />
74
- < img src = "./dist/png_512/1f62f.png" />
75
- < img src = "./dist/png_512/1f61e.png" />
76
- < img src = "./dist/png_512/1f621.png" />
77
- < img src = "./dist/png_512/1f6ab.png" />
98
+ < img src = "./dist/png_512/1f603.png" onClick = { this . blockCreate ( 'happy' ) } />
99
+ < img src = "./dist/png_512/1f62f.png" onClick = { this . blockCreate ( 'surprised' ) } />
100
+ < img src = "./dist/png_512/1f61e.png" onClick = { this . blockCreate ( 'sad' ) } />
101
+ < img src = "./dist/png_512/1f621.png" onClick = { this . blockCreate ( 'angry' ) } />
102
+ < img src = "./dist/png_512/1f6ab.png" onClick = { this . blockCreate ( 'no preference' ) } />
78
103
< div className = "nowTime" > { this . state . nowTime . toString ( ) } </ div >
79
104
</ div >
80
105
) ;
81
106
}
82
107
}
83
108
84
- /* ReactDOM.render(<MessageBlock
85
- textIn="Just a dream~~~"
86
- visitorIn="admin"
87
- timeIn={(new Date()).toString()}
88
- emotionIn="happy"
89
- />, document.getElementById('root')); */
90
-
91
- ReactDOM . render ( < MessageBoard /> , document . getElementById ( 'root' ) ) ;
109
+ ReactDOM . render ( < MessageBoard /> , document . getElementById ( 'root' ) ) ;
0 commit comments