Comment delete message

This commit is contained in:
ilya-bkv 2024-03-07 10:20:50 +03:00
parent d7f00cd962
commit 41e40ada9b
5 changed files with 22 additions and 16 deletions

View File

@ -525,5 +525,6 @@
"video": "video",
"view": "view",
"viewsWithCount": "{count} {count, plural, one {view} other {views}}",
"yesterday": "yesterday"
"yesterday": "yesterday",
"Failed to delete comment": "Failed to delete comment"
}

View File

@ -552,5 +552,6 @@
"video": "видео",
"view": "просмотр",
"viewsWithCount": "{count} {count, plural, one {просмотр} few {просмотрa} other {просмотров}}",
"yesterday": "вчера"
"yesterday": "вчера",
"Failed to delete comment": "Не удалось удалить комментарий"
}

View File

@ -64,14 +64,19 @@ export const Comment = (props: Props) => {
})
if (isConfirmed) {
await deleteReaction(props.comment.id)
// TODO: Учесть то что deleteReaction может вернуть error
if (props.onDelete) {
const { error } = await deleteReaction(props.comment.id)
const notificationType = error ? 'error' : 'success'
const notificationMessage = error
? t('Failed to delete comment')
: t('Comment successfully deleted')
await showSnackbar({ type: notificationType, body: notificationMessage })
if (!error && props.onDelete) {
props.onDelete(props.comment.id)
}
await showSnackbar({ body: t('Comment successfully deleted') })
}
} catch (error) {
await showSnackbar({ body: 'error' })
console.error('[deleteReaction]', error)
}
}

View File

@ -21,7 +21,7 @@ type ReactionsContextType = {
}) => Promise<Reaction[]>
createReaction: (reaction: ReactionInput) => Promise<void>
updateReaction: (reaction: ReactionInput) => Promise<Reaction>
deleteReaction: (id: number) => Promise<void>
deleteReaction: (id: number) => Promise<{ error: string }>
}
const ReactionsContext = createContext<ReactionsContextType>()
@ -84,15 +84,15 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
setReactionEntities(changes)
}
const deleteReaction = async (reaction_id: number): Promise<void> => {
const deleteReaction = async (reaction_id: number): Promise<{ error: string; reaction?: string }> => {
if (reaction_id) {
const { error } = await apiClient.destroyReaction(reaction_id)
if (error) {
await showSnackbar({ type: 'error', body: t(error) })
const result = await apiClient.destroyReaction(reaction_id)
if (!result.error) {
setReactionEntities({
[reaction_id]: undefined,
})
}
setReactionEntities({
[reaction_id]: undefined,
})
return result
}
}

View File

@ -135,7 +135,6 @@ export const apiClient = {
user?: string
}): Promise<AuthorFollows> => {
const response = await publicGraphQLClient.query(authorFollows, params).toPromise()
console.log('!!! response:', response)
return response.data.get_author_follows
},
@ -188,7 +187,7 @@ export const apiClient = {
destroyReaction: async (reaction_id: number) => {
const response = await apiClient.private.mutation(reactionDestroy, { reaction_id }).toPromise()
console.debug('[graphql.client.core] destroyReaction:', response)
return response.data.delete_reaction.reaction
return response.data.delete_reaction
},
updateReaction: async (reaction: ReactionInput) => {
const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise()