add useConfirm for comments deleting (#152)
* add useConfirm for comments deleting
This commit is contained in:
parent
039b60f022
commit
ef76664b21
|
@ -1,21 +1,26 @@
|
||||||
import styles from './Comment.module.scss'
|
|
||||||
import { Icon } from '../_shared/Icon'
|
|
||||||
import { AuthorCard } from '../Author/AuthorCard'
|
|
||||||
import { Show, createMemo, createSignal, For, lazy, Suspense } from 'solid-js'
|
import { Show, createMemo, createSignal, For, lazy, Suspense } from 'solid-js'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import type { Author, Reaction } from '../../graphql/types.gen'
|
import { getPagePath } from '@nanostores/router'
|
||||||
|
|
||||||
import MD from './MD'
|
import MD from './MD'
|
||||||
|
import { AuthorCard } from '../Author/AuthorCard'
|
||||||
import Userpic from '../Author/Userpic'
|
import Userpic from '../Author/Userpic'
|
||||||
|
import { CommentRatingControl } from './CommentRatingControl'
|
||||||
|
import { CommentDate } from './CommentDate'
|
||||||
|
import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated'
|
||||||
|
import { Icon } from '../_shared/Icon'
|
||||||
|
|
||||||
import { useSession } from '../../context/session'
|
import { useSession } from '../../context/session'
|
||||||
import { ReactionKind } from '../../graphql/types.gen'
|
import { useLocalize } from '../../context/localize'
|
||||||
import { useReactions } from '../../context/reactions'
|
import { useReactions } from '../../context/reactions'
|
||||||
import { useSnackbar } from '../../context/snackbar'
|
import { useSnackbar } from '../../context/snackbar'
|
||||||
import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated'
|
import { useConfirm } from '../../context/confirm'
|
||||||
import { useLocalize } from '../../context/localize'
|
|
||||||
import { CommentRatingControl } from './CommentRatingControl'
|
import type { Author, Reaction, ReactionKind } from '../../graphql/types.gen'
|
||||||
import { getPagePath } from '@nanostores/router'
|
|
||||||
import { router } from '../../stores/router'
|
import { router } from '../../stores/router'
|
||||||
import { CommentDate } from './CommentDate'
|
|
||||||
|
import styles from './Comment.module.scss'
|
||||||
|
|
||||||
const SimplifiedEditor = lazy(() => import('../Editor/SimplifiedEditor'))
|
const SimplifiedEditor = lazy(() => import('../Editor/SimplifiedEditor'))
|
||||||
|
|
||||||
|
@ -40,6 +45,9 @@ export const Comment = (props: Props) => {
|
||||||
actions: { createReaction, deleteReaction, updateReaction }
|
actions: { createReaction, deleteReaction, updateReaction }
|
||||||
} = useReactions()
|
} = useReactions()
|
||||||
|
|
||||||
|
const {
|
||||||
|
actions: { showConfirm }
|
||||||
|
} = useConfirm()
|
||||||
const {
|
const {
|
||||||
actions: { showSnackbar }
|
actions: { showSnackbar }
|
||||||
} = useSnackbar()
|
} = useSnackbar()
|
||||||
|
@ -51,8 +59,13 @@ export const Comment = (props: Props) => {
|
||||||
const remove = async () => {
|
const remove = async () => {
|
||||||
if (comment()?.id) {
|
if (comment()?.id) {
|
||||||
try {
|
try {
|
||||||
|
const isConfirmed = await showConfirm()
|
||||||
|
|
||||||
|
if (isConfirmed) {
|
||||||
await deleteReaction(comment().id)
|
await deleteReaction(comment().id)
|
||||||
showSnackbar({ body: t('Comment successfully deleted') })
|
|
||||||
|
await showSnackbar({ body: t('Comment successfully deleted') })
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[deleteReaction]', error)
|
console.error('[deleteReaction]', error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user