don't allow user to vote for his own comment

This commit is contained in:
igoradamenko
2018-05-12 00:32:24 +03:00
parent 98fdd6d2de
commit e54d979707
2 changed files with 8 additions and 5 deletions
+3 -1
View File
@@ -110,7 +110,9 @@ class Store {
}
getPinnedComments() {
return this.data.comments.reduce((acc, thread) => acc.concat(findPinnedComments(thread)), []);
const comments = this.data.comments || [];
return comments.reduce((acc, thread) => acc.concat(findPinnedComments(thread)), []);
}
}
+5 -4
View File
@@ -185,6 +185,7 @@ export default class Comment extends Component {
const { data, mix, mods = {} } = props;
const isAdmin = !guest && store.get('user').admin;
const isGuest = guest || !Object.keys(store.get('user')).length;
const isCurrentUser = (data.user && data.user.id) === (store.get('user') && store.get('user').id);
const o = {
...data,
@@ -274,9 +275,9 @@ export default class Comment extends Component {
<span className={b('comment__score', {}, { view: o.score.view })}>
<span
className={b('comment__vote', {}, { type: 'up', selected: scoreIncreased, disabled: isGuest })}
className={b('comment__vote', {}, { type: 'up', selected: scoreIncreased, disabled: isGuest || isCurrentUser })}
onClick={this.increaseScore}
title={isGuest ? 'Only authorized users are allowed to vote' : null}
title={isGuest ? 'Only authorized users are allowed to vote' : (isCurrentUser ? 'You can\'t vote for your own comment' : null)}
>Vote up</span>
<span className="comment__score-value">
@@ -285,9 +286,9 @@ export default class Comment extends Component {
<span
className={b('comment__vote', {}, { type: 'down', selected: scoreDecreased, disabled: isGuest })}
className={b('comment__vote', {}, { type: 'down', selected: scoreDecreased, disabled: isGuest || isCurrentUser })}
onClick={this.decreaseScore}
title={isGuest ? 'Only authorized users are allowed to vote' : null}
title={isGuest ? 'Only authorized users are allowed to vote' : (isCurrentUser ? 'You can\'t vote for your own comment' : null)}
>Vote down</span>
</span>
</div>