-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.html
More file actions
executable file
·155 lines (136 loc) · 3.88 KB
/
Post.html
File metadata and controls
executable file
·155 lines (136 loc) · 3.88 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html>
<head>
<title>Post</title>
<link href="post.css" rel="stylesheet"/>
<script src="http://fb.me/react-0.12.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.0.js"></script>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js"></script>
</head>
<body>
<div id="content"></div>
<script type="text/jsx">
var ImgPost = React.createClass({
render: function(){
return (
<div className="imgPost">
<img src={this.props.path}/>
</div>
);
}
});
var VoteBox = React.createClass({
render: function(){
return(
<p className="voteBox">{this.props.upvotes - this.props.downvotes}</p>
);
}
});
var Upvote = React.createClass({
getInitialState: function(){
return {votes: this.props.votes};
},
gainVote: function(e){
e.preventDefault();
this.setState({votes: this.state.votes + 1});
var id = this.props.id;
$.post('upvote.php', {id: id});
},
render: function() {
return (
<div className="upvote">
<form onSubmit={this.gainVote}>
<button class="upvote">Upvote</button>
</form>
</div>
);
}
});
var Downvote = React.createClass({
getInitialState: function(){
return {votes: this.props.votes};
},
loseVote: function(e){
e.preventDefault();
this.setState({votes: this.state.votes + 1});
var id = this.props.id;
$.post('downvote.php', {id: id});
},
render: function() {
return (
<div className="downvote">
<form onSubmit={this.loseVote}>
<button>Downvote</button>
</form>
</div>
);
}
});
var Flag = React.createClass({
render: function(){
return(
<div className="flag">
<form action="flag.php" method="post">
<input type="hidden" name="id" value={this.props.id} />
<input type="hidden" name="path" value={this.props.path} />
<input type="submit" name="submit" value="Report"/>
</form>
</div>
)
}
});
var Post = React.createClass({
render: function(){
return(
<div className="post">
<ImgPost path={this.props.path} />
<Upvote id={this.props.id} votes={this.props.upvotes}/>
<VoteBox upvotes={this.props.upvotes} downvotes={this.props.downvotes}/>
<Downvote id={this.props.id} votes={this.props.downvotes}/>
<Flag id={this.props.id} path={this.props.path}/>
</div>
);
}
});
// LIL LOVELY BIT THAT PUTS THE WHOLE SHEBANG TOGETHER
var PostStream = React.createClass({
getInitialState: function(){
return {posts: []};
},
loadContent: function(){
//get JSON array from PHP script
var self = this;
$.getJSON("get_uploads.php",
function(result){
var posts = result.map(function(p){
return{
id: p.PhotoID,
path: p.Path,
upvotes: parseInt(p.Upvotes),
downvotes: parseInt(p.Downvotes)
};
});
self.setState({posts: posts});
});
},
componentDidMount: function(){
this.loadContent();
setInterval(this.loadContent, this.props.pollInterval);
},
render: function(){
var posts = this.state.posts.map(function(p){
return <Post id={p.id} path={p.path} upvotes={p.upvotes} downvotes={p.downvotes} />
});
if(!posts.length){
posts = <p>Loading...</p>;
}
return(
<div className="photostream">{posts}</div>
);
}
});
React.render(<PostStream pollInterval={750} />, document.getElementById('content'));
</script>
</body>
</html>