-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
140 lines (128 loc) · 4.36 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Tutorial</title>
<link rel="stylesheet" href="css/wall.css">
<script src="build/react.min.js"></script>
<script src="build/react-dom.min.js"></script>
<script src="build/browser.min.js"></script>
<script src="build/jquery.min.js"></script>
<script src="build/ajaxPostReact.js"></script>
<script src="build/textToLink.js"></script>
</head>
<body>
<div id="container"></div>
</body>
<script type="text/babel">
//React code...
var WallForm=React.createClass({
getInitialState:function () {
return{'user_update':''}
},
updateChange:function (e) {
this.setState({'user_update':e.target.value});
},
updateSubmit:function (e) {
e.preventDefault();
var user_update=this.state.user_update.trim();
if(!user_update)
{
return;
}
else {
this.props.onUpdateSubmit({ user_update: user_update});
this.setState({'user_update':''});
}
},
render:function () {
return(
<form onSubmit={this.updateSubmit}>
<textarea ref="updateInput" value={this.state.user_update} onChange={this.updateChange}></textarea>
<input type="submit" value="Post" id="WallPost"/>
</form>
);
}
});
var WallUpdates=React.createClass({
textToLinkHTML: function(content){
var finalContent=textToLink(content);
return {__html: finalContent}
},
render:function () {
var updatesEach=this.props.data.map(function (update, index) {
return(<div className="feedBody" key={update.created}>
<img src={update.profile_pic} className="feedImg"/>
<div className="feedText">
<b>{update.name}</b>
<a href="#" className="feedDelete" value={index} data={update.update_id}
onClick={this.props.deleteUpdate} >X</a>
<span dangerouslySetInnerHTML={this.textToLinkHTML(update.user_update)} />
</div>
//coment block
</div>)
},this);
return(
<div id="wallFeed">
{updatesEach}
</div>
)
}
})
var WallFeed=React.createClass({
getInitialState:function () {
return {data:[]}
},
deleteUpdate: function(e)
{
var updateIndex=e.target.getAttribute('value');
var update_id=e.target.getAttribute('data');
var data='updateID='+update_id;
var reactThis=this;
reactThis.state.data.splice(updateIndex,1);
reactThis.setState({data: reactThis.state.data});
},
updateAjaxSubmit:function (update) {
var reactThis=this;
ajaxPostReact('updateFeed.json',update,reactThis,function (data) {
var updates=reactThis.state.data;
data.updates[0].user_update=update.user_update;
var newupdates=[data.updates[0]].concat(updates)
reactThis.setState({data:newupdates});
})
},
updateFromServer:function () {
var dataPost='';
var reactThis=this;
ajaxPostReact('newsFeed.json',dataPost,reactThis,function (data) {
reactThis.setState({data:data.updates})
})
},
componentDidMount:function () {
this.updateFromServer()
},
render:function () {
return(
<div>
<WallForm onUpdateSubmit={this.updateAjaxSubmit}/>
<WallUpdates data={this.state.data} deleteUpdate={this.deleteUpdate}/>
</div>
)
}
});
var WallContainer = React.createClass({
render : function () {
return(
<div id="wallContainer">
<h1>Social Network Test</h1>
<WallFeed/>
</div>
)
}
});
ReactDOM.render(
<WallContainer/>,
document.getElementById('container')
);
</script>
</html>