diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index ebbfd98c..54b6b570 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -38,12 +38,17 @@ export const Comment = (props: Props) => { const [loading, setLoading] = createSignal(false) const [editMode, setEditMode] = createSignal(false) const [clearEditor, setClearEditor] = createSignal(false) - const { author } = useSession() + const { author, session } = useSession() const { createReaction, deleteReaction, updateReaction } = useReactions() const { showConfirm } = useConfirm() const { showSnackbar } = useSnackbar() - const isCommentAuthor = createMemo(() => props.comment.created_by?.slug === author()?.slug) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.comment?.created_by?.id === author().id || session()?.user?.roles.includes('editor')), + ) + const comment = createMemo(() => props.comment) const body = createMemo(() => (comment().body || '').trim()) @@ -93,7 +98,8 @@ export const Comment = (props: Props) => { const handleUpdate = async (value) => { setLoading(true) try { - await updateReaction(props.comment.id, { + await updateReaction({ + id: props.comment.id, kind: ReactionKind.Comment, body: value, shout: props.comment.shout.id, @@ -108,9 +114,7 @@ export const Comment = (props: Props) => { return (
  • props.lastSeen, - })} + class={clsx(styles.comment, props.class, { [styles.isNew]: comment()?.created_at > props.lastSeen })} >
    @@ -189,7 +193,7 @@ export const Comment = (props: Props) => { {loading() ? t('Loading') : t('Reply')} - +
  • - +
  • - +
  • - {/**/} + {/**/} {/*
  • */} {/* { const { page } = useRouter() - const isSelected = page().route === props.routeName + const isSelected = page()?.route === props.routeName return (
  • Promise createReaction: (reaction: ReactionInput) => Promise - updateReaction: (id: number, reaction: ReactionInput) => Promise + updateReaction: (reaction: ReactionInput) => Promise deleteReaction: (id: number) => Promise } @@ -97,8 +97,8 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { await apiClient.destroyReaction(reaction) } - const updateReaction = async (id: number, input: ReactionInput): Promise => { - const reaction = await apiClient.updateReaction(id, input) + const updateReaction = async (input: ReactionInput): Promise => { + const reaction = await apiClient.updateReaction(input) setReactionEntities(reaction.id, reaction) } diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index 1fc303e4..a52c270e 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -178,15 +178,13 @@ export const apiClient = { console.debug('[graphql.client.core] createReaction: ', response) return response.data.create_reaction.reaction }, - destroyReaction: async (reaction: number) => { - const response = await apiClient.private.mutation(reactionDestroy, { reaction }).toPromise() + 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 }, - updateReaction: async (id: number, input: ReactionInput) => { - const response = await apiClient.private - .mutation(reactionUpdate, { id: id, reaction: input }) - .toPromise() + updateReaction: async (reaction: ReactionInput) => { + const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise() console.debug('[graphql.client.core] updateReaction:', response) return response.data.update_reaction.reaction }, diff --git a/src/graphql/mutation/core/reaction-update.ts b/src/graphql/mutation/core/reaction-update.ts index 03c32a04..6c20be49 100644 --- a/src/graphql/mutation/core/reaction-update.ts +++ b/src/graphql/mutation/core/reaction-update.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - mutation UpdateReactionMutation($id: Int!, $reaction: ReactionInput!) { - update_reaction(id: $id, reaction: $reaction) { + mutation UpdateReactionMutation($reaction: ReactionInput!) { + update_reaction(reaction: $reaction) { error reaction { id