showConfirmAppointAsAdmin: boolean;
collapsed: boolean;
viewSource: boolean;
+ my_vote: number;
+ score: number;
}
interface CommentNodeProps {
showConfirmTransferCommunity: false,
showConfirmAppointAsMod: false,
showConfirmAppointAsAdmin: false,
+ my_vote: this.props.node.comment.my_vote,
+ score: this.props.node.comment.score,
};
constructor(props: any, context: any) {
>
<button
className={`btn p-0 ${
- node.comment.my_vote == 1 ? 'text-info' : 'text-muted'
+ this.state.my_vote == 1 ? 'text-info' : 'text-muted'
}`}
onClick={linkEvent(node, this.handleCommentLike)}
>
<use xlinkHref="#icon-arrow-up"></use>
</svg>
</button>
- <div class={`font-weight-bold text-muted`}>
- {node.comment.score}
- </div>
+ <div class={`font-weight-bold text-muted`}>{this.state.score}</div>
{WebSocketService.Instance.site.enable_downvotes && (
<button
className={`btn p-0 ${
- node.comment.my_vote == -1 ? 'text-danger' : 'text-muted'
+ this.state.my_vote == -1 ? 'text-danger' : 'text-muted'
}`}
onClick={linkEvent(node, this.handleCommentDisLike)}
>
}
handleCommentLike(i: CommentNodeI) {
+ this.state.my_vote = i.comment.my_vote == 1 ? 0 : 1;
+ let add = 1;
+ if (i.comment.my_vote == 1) {
+ add = -1;
+ } else if (i.comment.my_vote == -1) {
+ add = 2;
+ }
+
+ this.state.score = i.comment.score + add;
+ this.setState(this.state);
+
let form: CommentLikeForm = {
comment_id: i.comment.id,
post_id: i.comment.post_id,
- score: i.comment.my_vote == 1 ? 0 : 1,
+ score: this.state.my_vote,
};
WebSocketService.Instance.likeComment(form);
}
handleCommentDisLike(i: CommentNodeI) {
+ this.state.my_vote = i.comment.my_vote == -1 ? 0 : -1;
+ let add = -1;
+ if (i.comment.my_vote == 1) {
+ add = -2;
+ } else if (i.comment.my_vote == -1) {
+ add = 1;
+ }
+ this.state.score = i.comment.score + add;
+ this.setState(this.state);
+
let form: CommentLikeForm = {
comment_id: i.comment.id,
post_id: i.comment.post_id,
- score: i.comment.my_vote == -1 ? 0 : -1,
+ score: this.state.my_vote,
};
WebSocketService.Instance.likeComment(form);
}
showConfirmTransferCommunity: boolean;
imageExpanded: boolean;
viewSource: boolean;
+ my_vote: number;
+ score: number;
}
interface PostListingProps {
showConfirmTransferCommunity: false,
imageExpanded: false,
viewSource: false,
+ my_vote: this.props.post.my_vote,
+ score: this.props.post.score,
};
constructor(props: any, context: any) {
>
<button
className={`btn p-0 ${
- post.my_vote == 1 ? 'text-info' : 'text-muted'
+ this.state.my_vote == 1 ? 'text-info' : 'text-muted'
}`}
onClick={linkEvent(this, this.handlePostLike)}
>
<use xlinkHref="#icon-arrow-up"></use>
</svg>
</button>
- <div class={`font-weight-bold text-muted`}>{post.score}</div>
+ <div class={`font-weight-bold text-muted`}>{this.state.score}</div>
{WebSocketService.Instance.site.enable_downvotes && (
<button
className={`btn p-0 ${
- post.my_vote == -1 ? 'text-danger' : 'text-muted'
+ this.state.my_vote == -1 ? 'text-danger' : 'text-muted'
}`}
onClick={linkEvent(this, this.handlePostDisLike)}
>
get isAdmin(): boolean {
return (
this.props.admins &&
- isMod(this.props.admins.map(a => a.id), this.props.post.creator_id)
+ isMod(
+ this.props.admins.map(a => a.id),
+ this.props.post.creator_id
+ )
);
}
}
handlePostLike(i: PostListing) {
+ this.state.my_vote = i.props.post.my_vote == 1 ? 0 : 1;
+ let add = 1;
+ if (i.props.post.my_vote == 1) {
+ add = -1;
+ } else if (i.props.post.my_vote == -1) {
+ add = 2;
+ }
+
+ this.state.score = i.props.post.score + add;
+ this.setState(this.state);
+
let form: CreatePostLikeForm = {
post_id: i.props.post.id,
- score: i.props.post.my_vote == 1 ? 0 : 1,
+ score: this.state.my_vote,
};
WebSocketService.Instance.likePost(form);
}
handlePostDisLike(i: PostListing) {
+ this.state.my_vote = i.props.post.my_vote == -1 ? 0 : -1;
+ let add = -1;
+ if (i.props.post.my_vote == 1) {
+ add = -2;
+ } else if (i.props.post.my_vote == -1) {
+ add = 1;
+ }
+ this.state.score = i.props.post.score + add;
+ this.setState(this.state);
+
let form: CreatePostLikeForm = {
post_id: i.props.post.id,
- score: i.props.post.my_vote == -1 ? 0 : -1,
+ score: this.state.my_vote,
};
WebSocketService.Instance.likePost(form);
}