forked from barcode-network/workshop-final
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
124 lines (88 loc) · 3.2 KB
/
App.js
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
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
constructor(props) {
super(props)
// Use these state variables to save the user comment and store a list of previously added comments
this.state = {
comment: '',
messages: [],
}
}
componentDidMount() {
this.setState({ comment: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisee gravida sem sit amet molestie porttitor." })
}
handleSubmit = () => {
var myDate = new Date();
const {messages} = this.state;
var myDate = myDate.toLocaleDateString();
messages.push({
message_value: this.state.comment,
message_author: "Jack Smith",
message_photo: "https://api.adorable.io/avatars/285/avatar_user_3.png",
message_timestamp: myDate
})
this.setState({messages:messages})
console.log(this.state.comment)
// Modify this function to handle user submissions and update state
}
handleInputChange(e) {
e.persist()
var name = e.target.name
var value = e.target.value
this.setState((prevState) => {
return {
[name]: value,
}
})
}
render() {
const {messages} = this.state;
const messagesTable = messages.map(function (item) {
return (
<li className="comment author-comment">
<div className="info">
<a href="#">Jack Smith</a>
<span>{item.message_timestamp}</span>
</div>
<a className="avatar" href="#">
<img src="https://api.adorable.io/avatars/285/avatar_user_3.png" width="35" alt="Profile Avatar" title="Jack Smith" />
</a>
<p>{item.message_value}</p>
</li>
)
})
return (
<div classNameName="App">
<ul className="comment-section">
{/* Replace the contents of comment-section with the appended list of user comments */}
<li className="comment author-comment">
<div className="info">
<a href="#">Jack Smith</a>
<span>1 hour ago</span>
</div>
<a className="avatar" href="#">
<img src="https://api.adorable.io/avatars/285/avatar_user_3.png" width="35" alt="Profile Avatar" title="Jack Smith" />
</a>
<p>Random comment goes here</p>
</li>
{messagesTable}
<li className="write-new">
<form>
<textarea placeholder="Write your comment here" name="comment" onChange={evt => this.handleInputChange(evt)}></textarea>
<div>
<img src="https://api.adorable.io/avatars/285/avatar_user_4.png" width="35" alt="Profile of Bradley Jones" title="Bradley Jones" />
<button type="button" onClick={this.handleSubmit}>Submit</button>
</div>
</form>
</li>
</ul>
<footer>
<a href="http://tutorialzine.com/2015/11/using-flexbox-to-create-a-responsive-comment-section/">Inspired by this tutorial</a>
</footer>
</div>
);
}
}
export default App;