Skip to content

Commit 38dc52c

Browse files
committed
message-board version 1.0
1 parent 99d94cb commit 38dc52c

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

webProg2016/final/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
.MessageBoard > img {
5656
display: inline-block;
57+
cursor: pointer;
5758
width: 32px;
5859
height: 32px;
5960
}

webProg2016/final/src/message-board.js

+33-15
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,68 @@ class MessageBoard extends Component {
4242
nowTime: new Date(),
4343
blockArr: [
4444
<MessageBlock
45+
key={`message-left number ${0}`}
4546
orderIn={0}
4647
textIn="Go Ahead!"
4748
emotionIn="happy"
4849
/>,
4950
<MessageBlock
51+
key={`message-left number ${1}`}
5052
orderIn={1}
5153
textIn="Let's Chat!"
5254
emotionIn="happy"
5355
/>
5456
],
5557
};
58+
this.visitorText = '';
59+
this.visitorName = '';
60+
this.blockCreate = this.blockCreate.bind(this);
5661
}
5762
componentDidMount() {
5863
this.startTick = setInterval(() => {
5964
this.setState({ nowTime: new Date() });
6065
}, 1000);
6166
}
6267
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+
}
6388
render() {
6489
return (
6590
<div className="MessageBoard">
6691
<div className="blockArr">{this.state.blockArr}</div>
6792
<textarea placeholder="Text here to leave a message..." onKeyUp={e => {
68-
this.visitorName = e.target.value;
93+
this.visitorText = e.target.value;
6994
}} />
7095
<input placeholder="Nickname, please." onKeyUp={e => {
71-
this.visitorText = e.target.value;
96+
this.visitorName = e.target.value;
7297
}} />
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')} />
78103
<div className="nowTime">{this.state.nowTime.toString()}</div>
79104
</div>
80105
);
81106
}
82107
}
83108

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

Comments
 (0)