Skip to content

Instantly share code, notes, and snippets.

@Vivekbhusal
Created March 9, 2016 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vivekbhusal/a62bc0dc88daf4c1008c to your computer and use it in GitHub Desktop.
Save Vivekbhusal/a62bc0dc88daf4c1008c to your computer and use it in GitHub Desktop.
class MyPosts extends Component{
constructor(props) {
super(props);
this.handleDeletePost = this.handleDeletePost.bind(this);
}
handleDeletePost(postID) {
const {dispatch} = this.props;
dispatch(deletePostsRequest(postID))
}
render() {
return (
<div>
<div className="post-sidebar-title" dangerouslySetInnerHTML= {{__html: title}}></div>
<span className="post-actions">
{attachDetachAction}
<span
onClick={this.handleDeleteClipping.bind(this, id)}
className="remove-post"><i className="glyphicon glyphicon-remove"></i></span>
</span>
<div className="post-sidebar-source">{source}</div>
<div className="post-sidebar-content" dangerouslySetInnerHTML= {{__html: content}}></div>
</div>
</div>
)
}
}
##reducer.js
export function deletePostsRequest(postID) {
let API = API_DELETE_POST;
return dispatch => {
dispatch(deletePosts(postID));
return fetch(API.url(postID), {
method: API.type,
credentials: 'same-origin'
}).then(function(response) {
if(!response.ok) {
//revert back
}
});
}
}
function deletePosts(postID) {
return {
type: DELETE_POST,
postID
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment