Skip to content

Commit

Permalink
Remove the completed solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Nair committed Feb 8, 2016
1 parent b9fddb4 commit 7738344
Showing 1 changed file with 6 additions and 124 deletions.
130 changes: 6 additions & 124 deletions js/script.js
@@ -1,128 +1,10 @@
var CallbackFacebook = React.createClass({
render: function() {
return (
<div>
<TopBar/>
<Feed/>
</div>
);
}
});

var TopBar = React.createClass({
render: function() {
return (
<div id="top-bar">
<h1>Callback Facebook</h1>
</div>
);
}
});

var Feed = React.createClass({
getInitialState: function() {
return {
posts: []
};
},
addPost: function(post) {
var copiedPosts = this.state.posts.slice();
copiedPosts.unshift(post);
this.setState({
posts: copiedPosts
});
},
render: function() {
return (
<div id="feed">
<Status addPost={this.addPost}/>
<Posts posts={this.state.posts}/>
</div>
);
}
});

var Status = React.createClass({
getInitialState: function(event) {
return {
status: ""
};
},
handleSubmit: function(event) {
event.preventDefault();
var statusInput = event.target.querySelector('input[name="status"]');
this.setState({
status: ""
});
this.props.addPost({
author: "Vivek",
content: statusInput.value
});
},
handleStatusChange: function(event) {
var newStatus = event.target.value.substr(0, 20);
this.setState({
status: newStatus
});
},
render: function() {
return (
<form onSubmit={this.handleSubmit}>
<input type="text" name="status" placeholder="What's on your mind?"
value={this.state.status} onChange={this.handleStatusChange}/>
<input type="submit" defaultValue="Submit Status"/>
</form>
);
}
});

var Posts = React.createClass({
getInitialState: function() {
return {
posts: []
};
},
render: function() {
var posts = this.props.posts.map(function(post, index) {
return (
<Post key={index} author={post.author} content={post.content} />
);
});
return (
<ul id="stories">
{posts}
</ul>
);
}
});

var Post = React.createClass({
getInitialState: function() {
return {
numberLikes: 0
};
},
incrementLikeCount: function(event) {
event.preventDefault();
this.setState({
numberLikes: this.state.numberLikes + 1
});
},
render: function() {
return (
<li className="story">
<h2>{this.props.author}</h2>
<p>{this.props.content}</p>
<div className="story-likes">
{this.state.numberLikes} likes
<a onClick={this.incrementLikeCount} href="#" className="like">like</a>
</div>
</li>
);
}
});

ReactDOM.render(
<CallbackFacebook/>,
document.getElementById('facebook')
);

var CallbackFacebook = React.createClass({
render: function() {
// Write your codez here
}
});

0 comments on commit 7738344

Please sign in to comment.