[146] handle voting error

This commit is contained in:
ilya-bkv 2023-03-09 20:01:39 +03:00
parent 06e68fca4a
commit c421467f04
5 changed files with 24 additions and 17 deletions

View File

@ -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", "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", "zine": "zine",
"By time": "By time", "By time": "By time",
"New only": "New only" "New only": "New only",
"You can't vote twice": "You cannot vote twice"
} }

View File

@ -248,6 +248,5 @@
"user already exist": "пользователь уже существует", "user already exist": "пользователь уже существует",
"view": "просмотр", "view": "просмотр",
"zine": "журнал", "zine": "журнал",
"By time": "По порядку", "By time": "По порядку"
"New only": "Только новые"
} }

View File

@ -7,14 +7,19 @@ import { useReactions } from '../../context/reactions'
import { createMemo, For } from 'solid-js' import { createMemo, For } from 'solid-js'
import { loadShout } from '../../stores/zine/articles' import { loadShout } from '../../stores/zine/articles'
import { Popup } from '../_shared/Popup' import { Popup } from '../_shared/Popup'
import { useLocalize } from '../../context/localize'
import { useSnackbar } from '../../context/snackbar'
type Props = { type Props = {
comment: Reaction comment: Reaction
} }
export const CommentRatingControl = (props: Props) => { export const CommentRatingControl = (props: Props) => {
const { t } = useLocalize()
const { userSlug } = useSession() const { userSlug } = useSession()
const {
actions: { showSnackbar }
} = useSnackbar()
const { const {
reactionEntities, reactionEntities,
actions: { createReaction, deleteReaction, loadReactionsBy } actions: { createReaction, deleteReaction, loadReactionsBy }
@ -52,16 +57,20 @@ export const CommentRatingControl = (props: Props) => {
} }
const handleRatingChange = async (isUpvote: boolean) => { const handleRatingChange = async (isUpvote: boolean) => {
if (isUpvoted()) { try {
await deleteCommentReaction(ReactionKind.Like) if (isUpvoted()) {
} else if (isDownvoted()) { await deleteCommentReaction(ReactionKind.Like)
await deleteCommentReaction(ReactionKind.Dislike) } else if (isDownvoted()) {
} else { await deleteCommentReaction(ReactionKind.Dislike)
await createReaction({ } else {
kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike, await createReaction({
shout: props.comment.shout.id, kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike,
replyTo: props.comment.id shout: props.comment.shout.id,
}) replyTo: props.comment.id
})
}
} catch (e) {
showSnackbar({ type: 'error', body: t('Error') })
} }
await loadShout(props.comment.shout.slug) await loadShout(props.comment.shout.slug)
@ -72,7 +81,6 @@ export const CommentRatingControl = (props: Props) => {
return ( return (
<div class={styles.commentRating}> <div class={styles.commentRating}>
{!canVote()}
<button <button
role="button" role="button"
disabled={!canVote() || !userSlug()} disabled={!canVote() || !userSlug()}

View File

@ -6,7 +6,6 @@ import { clsx } from 'clsx'
import styles from './Settings.module.scss' import styles from './Settings.module.scss'
import { useProfileForm } from '../../context/profile' import { useProfileForm } from '../../context/profile'
import validateUrl from '../../utils/validateUrl' import validateUrl from '../../utils/validateUrl'
import { createFileUploader, UploadFile } from '@solid-primitives/upload' import { createFileUploader, UploadFile } from '@solid-primitives/upload'
import { Loading } from '../../components/_shared/Loading' import { Loading } from '../../components/_shared/Loading'
import { useSession } from '../../context/session' import { useSession } from '../../context/session'

View File

@ -1,3 +1,3 @@
// debug nested objects console.log('message', clone(obj)) // debug nested objects console.log('message', clone(obj))
export const clone = <T>(obj: T) => JSON.parse(JSON.stringify(obj)) export const clone = <T>(obj: T): T => JSON.parse(JSON.stringify(obj))