Comment delete message
This commit is contained in:
parent
d7f00cd962
commit
41e40ada9b
|
@ -525,5 +525,6 @@
|
||||||
"video": "video",
|
"video": "video",
|
||||||
"view": "view",
|
"view": "view",
|
||||||
"viewsWithCount": "{count} {count, plural, one {view} other {views}}",
|
"viewsWithCount": "{count} {count, plural, one {view} other {views}}",
|
||||||
"yesterday": "yesterday"
|
"yesterday": "yesterday",
|
||||||
|
"Failed to delete comment": "Failed to delete comment"
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,5 +552,6 @@
|
||||||
"video": "видео",
|
"video": "видео",
|
||||||
"view": "просмотр",
|
"view": "просмотр",
|
||||||
"viewsWithCount": "{count} {count, plural, one {просмотр} few {просмотрa} other {просмотров}}",
|
"viewsWithCount": "{count} {count, plural, one {просмотр} few {просмотрa} other {просмотров}}",
|
||||||
"yesterday": "вчера"
|
"yesterday": "вчера",
|
||||||
|
"Failed to delete comment": "Не удалось удалить комментарий"
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,14 +64,19 @@ export const Comment = (props: Props) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isConfirmed) {
|
if (isConfirmed) {
|
||||||
await deleteReaction(props.comment.id)
|
const { error } = await deleteReaction(props.comment.id)
|
||||||
// TODO: Учесть то что deleteReaction может вернуть error
|
const notificationType = error ? 'error' : 'success'
|
||||||
if (props.onDelete) {
|
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)
|
props.onDelete(props.comment.id)
|
||||||
}
|
}
|
||||||
await showSnackbar({ body: t('Comment successfully deleted') })
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
await showSnackbar({ body: 'error' })
|
||||||
console.error('[deleteReaction]', error)
|
console.error('[deleteReaction]', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ type ReactionsContextType = {
|
||||||
}) => Promise<Reaction[]>
|
}) => Promise<Reaction[]>
|
||||||
createReaction: (reaction: ReactionInput) => Promise<void>
|
createReaction: (reaction: ReactionInput) => Promise<void>
|
||||||
updateReaction: (reaction: ReactionInput) => Promise<Reaction>
|
updateReaction: (reaction: ReactionInput) => Promise<Reaction>
|
||||||
deleteReaction: (id: number) => Promise<void>
|
deleteReaction: (id: number) => Promise<{ error: string }>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReactionsContext = createContext<ReactionsContextType>()
|
const ReactionsContext = createContext<ReactionsContextType>()
|
||||||
|
@ -84,15 +84,15 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
|
||||||
setReactionEntities(changes)
|
setReactionEntities(changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteReaction = async (reaction_id: number): Promise<void> => {
|
const deleteReaction = async (reaction_id: number): Promise<{ error: string; reaction?: string }> => {
|
||||||
if (reaction_id) {
|
if (reaction_id) {
|
||||||
const { error } = await apiClient.destroyReaction(reaction_id)
|
const result = await apiClient.destroyReaction(reaction_id)
|
||||||
if (error) {
|
if (!result.error) {
|
||||||
await showSnackbar({ type: 'error', body: t(error) })
|
setReactionEntities({
|
||||||
|
[reaction_id]: undefined,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
setReactionEntities({
|
return result
|
||||||
[reaction_id]: undefined,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,6 @@ export const apiClient = {
|
||||||
user?: string
|
user?: string
|
||||||
}): Promise<AuthorFollows> => {
|
}): Promise<AuthorFollows> => {
|
||||||
const response = await publicGraphQLClient.query(authorFollows, params).toPromise()
|
const response = await publicGraphQLClient.query(authorFollows, params).toPromise()
|
||||||
console.log('!!! response:', response)
|
|
||||||
return response.data.get_author_follows
|
return response.data.get_author_follows
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -188,7 +187,7 @@ export const apiClient = {
|
||||||
destroyReaction: async (reaction_id: number) => {
|
destroyReaction: async (reaction_id: number) => {
|
||||||
const response = await apiClient.private.mutation(reactionDestroy, { reaction_id }).toPromise()
|
const response = await apiClient.private.mutation(reactionDestroy, { reaction_id }).toPromise()
|
||||||
console.debug('[graphql.client.core] destroyReaction:', response)
|
console.debug('[graphql.client.core] destroyReaction:', response)
|
||||||
return response.data.delete_reaction.reaction
|
return response.data.delete_reaction
|
||||||
},
|
},
|
||||||
updateReaction: async (reaction: ReactionInput) => {
|
updateReaction: async (reaction: ReactionInput) => {
|
||||||
const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise()
|
const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user