diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 4d903442..3f230dc2 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -231,5 +231,6 @@ "Your name will appear on your profile page and as your signature in publications, comments and responses.": "Your name will appear on your profile page and as your signature in publications, comments and responses", "zine": "zine", "By time": "By time", - "New only": "New only" + "New only": "New only", + "You can't vote twice": "You cannot vote twice" } diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index edbae3ef..61f42e27 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -248,6 +248,5 @@ "user already exist": "пользователь уже существует", "view": "просмотр", "zine": "журнал", - "By time": "По порядку", - "New only": "Только новые" + "By time": "По порядку" } diff --git a/src/components/Article/CommentRatingControl.tsx b/src/components/Article/CommentRatingControl.tsx index 109200f4..69598129 100644 --- a/src/components/Article/CommentRatingControl.tsx +++ b/src/components/Article/CommentRatingControl.tsx @@ -7,14 +7,19 @@ import { useReactions } from '../../context/reactions' import { createMemo, For } from 'solid-js' import { loadShout } from '../../stores/zine/articles' import { Popup } from '../_shared/Popup' +import { useLocalize } from '../../context/localize' +import { useSnackbar } from '../../context/snackbar' type Props = { comment: Reaction } export const CommentRatingControl = (props: Props) => { + const { t } = useLocalize() const { userSlug } = useSession() - + const { + actions: { showSnackbar } + } = useSnackbar() const { reactionEntities, actions: { createReaction, deleteReaction, loadReactionsBy } @@ -52,16 +57,20 @@ export const CommentRatingControl = (props: Props) => { } const handleRatingChange = async (isUpvote: boolean) => { - if (isUpvoted()) { - await deleteCommentReaction(ReactionKind.Like) - } else if (isDownvoted()) { - await deleteCommentReaction(ReactionKind.Dislike) - } else { - await createReaction({ - kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike, - shout: props.comment.shout.id, - replyTo: props.comment.id - }) + try { + if (isUpvoted()) { + await deleteCommentReaction(ReactionKind.Like) + } else if (isDownvoted()) { + await deleteCommentReaction(ReactionKind.Dislike) + } else { + await createReaction({ + kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike, + shout: props.comment.shout.id, + replyTo: props.comment.id + }) + } + } catch (e) { + showSnackbar({ type: 'error', body: t('Error') }) } await loadShout(props.comment.shout.slug) @@ -72,7 +81,6 @@ export const CommentRatingControl = (props: Props) => { return (