8000 Delete posts from My Profile page by alkalai2 · Pull Request #89 · alkalai2/CrowdSauce · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Delete posts from My Profile page #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions public/js/react_components/PostRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,19 @@ var Post = React.createClass({
currentImages: this.props.data.images
}
},
//called when postlist reacts to changes in its data
//sets state values to new properties
componentWillReceiveProps: function(nextProps){
if(nextProps){
this.setState({
title: nextProps.data.title,
notes: nextProps.data.notes,
images: nextProps.data.images,
currenttitle: nextProps.data.title,
currentnotes: nextProps.data.notes,
currentImages: nextProps.data.images
});}
},
// Callbacks to handle Post editing.
handleTitleChange: function(event) {
this.setState({currenttitle: event.target.value});
Expand Down Expand Up @@ -547,6 +560,13 @@ var Post = React.createClass({
directions={this.props.data.directions}/>
}
},

deletePost: function(){
this.setState({editing: false})
var postIdToDelete = this.props.data.postId;
this.props.handleDeletion(postIdToDelete);
},

render : function() {
var recipe = this.checkForLink(this.state.editing);
var favoriteHeart = !this.props.favoriteAble ? "" : <FavoriteStar data={this.props.data} />;
Expand Down Expand Up @@ -617,6 +637,9 @@ var Post = React.createClass({
<Tags className = "tagset" handleSearch={this.props.handleSearch} postId={this.props.data.postId}/>
{favoriteHeart}
</div>
<div>
<Button className="delete-button" bsSize="small" Post</Button>
</div>
<Comment id={this.props.data.postId}/>
</div>
</Panel>
Expand Down Expand Up @@ -674,28 +697,68 @@ var Post = React.createClass({
// The final parent class of all above controls that finally
// renders all posts as a list of posts as a feed/profile/whatver
var PostList = React.createClass({
getInitialState : function() {
return { data : []};
},

//deletion of a post, carried out by calling the API and updating local state
handlePostDeletion : function(postId) {
var postIdToDelete = postId;
console.log("goop" + postIdToDelete);
var url = 'http://localhost:3000/api/posts'
jQuery.ajax({
url: url,
type: 'DELETE',
headers: {
'accessToken': fbAccessToken,
'userId': fbUserID
},
dataType: 'json',
data: {
'postId': postIdToDelete
},
success: function(data) {
console.log("removing " + postIdToDelete + " from post list")
data = this.state.data.filter(function(e){return e.postId!==postIdToDelete})
console.log(this.state.data)
this.setState({data: data},function(){console.log(this.state.data)});
this.forceUpdate()
}.bind(this),
error: function(xhr, status, err) {
console.error(status, err.toString());
}.bind(this)
});
},

//needed because data comes in late due to server loading time
componentWillReceiveProps: function(nextProps){
this.setState({data:nextProps.data});
},

render: function() {
var favoriteAble = this.props.favoriteAble
var profileNavigation=this.props.profileNavigation
var handleSearch=this.props.handleSearch
var editable=this.props.editable
var addNames=this.props.addNames
var self = this
// if no posts, display a 'no posts image'
var toDisplay = <NoPostsDisplay errorMsg={this.props.errorMsg}/>
// add search bar
if (this.props.data && this.props.data.length > 0) {
if (this.state.data && this.state.data.length > 0) {
toDisplay =
<div>
{
(this.props.data).map(function(post_data) {
(this.state.data).map(function(post_data) {
return (
<Post
data={post_data}
favoriteAble={favoriteAble}
editable={editable}
addNames={addNames}
handleSearch={handleSearch}
profileNavigation={profileNavigation}/>
profileNavigation={profileNavigation}
handleDeletion={self.handlePostDeletion}/>
)
})
}
Expand Down
0