forked from nypeach/MyTechnicalJournal-Old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.jsx
114 lines (98 loc) · 2.96 KB
/
delete.jsx
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
/* eslint-disable react/destructuring-assignment */
import React from 'react';
import SocialPost from '../social/SocialPost';
import axios from 'axios';
import Checkbox from './Checkbox';
class ManagePosts extends React.Component {
constructor(props) {
super(props);
this.state = {
allPosts: [],
selectedCheckboxes: new Set(),
hide: false
};
this.getAllPosts = this.getAllPosts.bind(this);
this.toggleCheckbox = this.toggleCheckbox.bind(this);
this.onHideClick = this.onHideClick.bind(this);
}
// componentWillMount() {
// this.selectedCheckboxes = new Set();
// }
componentDidMount() {
this.getAllPosts();
}
getAllPosts() {
axios.get('api/post/reported')
.then((res) => {
this.setState({ allPosts: res.data });
})
.catch((err) => console.log('ERROR GETTING POSTS: ', err));
}
toggleCheckbox(label) {
if (this.selectedCheckboxes.has(label)) {
this.selectedCheckboxes.delete(label);
} else {
this.selectedCheckboxes.add(label);
}
}
handleFormSubmit() {
preventDefault();
// We may not use the following code. Instead it will be a 'put' request
for (const checkbox of this.selectedCheckboxes) {
console.log(checkbox, 'is selected.');
}
}
createCheckbox(label) {
return
<Checkbox
label={label}
handleCheckboxChange={this.toggleCheckbox}
key={label}
/>
}
render() {
const allPosts = this.state.allPosts;
console.log('ALL POSTS', allPosts);
return (
<div>
<div className="manage-heading">MANAGE POSTS</div>
<div className="listItems"><ul className="no-bullets">
{allPosts.map((post) => (
<li key={post.id}>
<div class="mytextdiv">
<div class="mytexttitle manage-mytext">
{post.name_user + " " + post.last_name} </div>
<div class="divider"></div>
</div>
{this.createCheckbox(post.id)}
<br></br>
Post Name: {post.name}
<br></br>
Created: {post.created_at}
<br></br>
Location: {post.location_post}
<br></br>
Post: {post.message_post}
<br></br>
{post.image_url}
{post.run}
</li>
))}</ul>
</div>
{/* {allPosts.map((post) => (
<div>{post.name_user + " " + post.last_name}
<label>
Hide?:
<input
name="isGoing"
type="checkbox"
checked={this.state.hide}
onChange={this.onHideClick} />
</label>
<SocialPost key={post.date + post.post} propic={post.propic} name={post.name} date={post.created_at} location={post.location_post} image={post.image_url} run={post.run} post={post.message_post} /></div>
))} */}
</div>
);
}
}
export default ManagePosts;