Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vivek Nair
committed
Feb 8, 2016
1 parent
b9fddb4
commit 7738344
Showing
1 changed file
with
6 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
}); |