From 98264cfce7a9f713a663914af1daaef5d2cad274 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 13:21:25 +0300 Subject: [PATCH 1/9] canEdit-fix --- src/components/Article/Comment/Comment.tsx | 12 ++++++------ src/components/Article/FullArticle.tsx | 9 +++++++-- src/components/Feed/ArticleCard/ArticleCard.tsx | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index d6af579f..50a8f9c5 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -38,12 +38,14 @@ 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( + () => props.comment.created_by?.slug === author()?.slug || session()?.user?.roles.includes('editor'), + ) const comment = createMemo(() => props.comment) const body = createMemo(() => (comment().body || '').trim()) @@ -108,9 +110,7 @@ export const Comment = (props: Props) => { return (
  • props.lastSeen, - })} + class={clsx(styles.comment, props.class, { [styles.isNew]: comment()?.created_at > props.lastSeen })} >
    @@ -189,7 +189,7 @@ export const Comment = (props: Props) => { {loading() ? t('Loading') : t('Reply')} - +
  • - +
  • - +
  • - {/**/} + {/**/} {/*
  • */} {/* Date: Fri, 16 Feb 2024 19:22:50 +0300 Subject: [PATCH 5/9] minor-fix --- src/components/Nav/Header/Link.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Nav/Header/Link.tsx b/src/components/Nav/Header/Link.tsx index c041c4d0..98711721 100644 --- a/src/components/Nav/Header/Link.tsx +++ b/src/components/Nav/Header/Link.tsx @@ -17,7 +17,7 @@ type Props = { export const Link = (props: Props) => { const { page } = useRouter() - const isSelected = page().route === props.routeName + const isSelected = page()?.route === props.routeName return (
  • Date: Fri, 16 Feb 2024 19:27:38 +0300 Subject: [PATCH 6/9] delete-reaction-fix-header-link-fix --- src/components/Nav/Header/Link.tsx | 2 +- src/graphql/client/core.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Nav/Header/Link.tsx b/src/components/Nav/Header/Link.tsx index 98711721..6bf639b5 100644 --- a/src/components/Nav/Header/Link.tsx +++ b/src/components/Nav/Header/Link.tsx @@ -21,7 +21,7 @@ export const Link = (props: Props) => { return (
  • { - const response = await apiClient.private.mutation(reactionDestroy, { id: id }).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 }, From b295ba0dbf62be7418497d4355c2ea7d16743fcf Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 19:58:24 +0300 Subject: [PATCH 7/9] update-reaction-query-fix --- src/components/Article/Comment/Comment.tsx | 3 ++- src/context/reactions.tsx | 6 +++--- src/graphql/client/core.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index 0df0a748..f0d468a2 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -96,7 +96,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, diff --git a/src/context/reactions.tsx b/src/context/reactions.tsx index 48da0594..ae4c7b95 100644 --- a/src/context/reactions.tsx +++ b/src/context/reactions.tsx @@ -18,7 +18,7 @@ type ReactionsContextType = { offset?: number }) => Promise createReaction: (reaction: ReactionInput) => Promise - updateReaction: (id: number, reaction: ReactionInput) => Promise + updateReaction: (reaction: ReactionInput) => Promise deleteReaction: (id: number) => Promise } @@ -88,8 +88,8 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { } } - 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 bd6571c1..e83d4872 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -183,9 +183,9 @@ export const apiClient = { console.debug('[graphql.client.core] destroyReaction:', response) return response.data.delete_reaction.reaction }, - updateReaction: async (id: number, input: ReactionInput) => { + updateReaction: async (reaction: ReactionInput) => { const response = await apiClient.private - .mutation(reactionUpdate, { id: id, reaction: input }) + .mutation(reactionUpdate, { reaction }) .toPromise() console.debug('[graphql.client.core] updateReaction:', response) return response.data.update_reaction.reaction From 6cc6b4f5ac3b570378553ee23db7355216118149 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 20:04:05 +0300 Subject: [PATCH 8/9] id-optional-fix-2 --- src/components/Article/Comment/Comment.tsx | 6 ++++-- src/components/Article/FullArticle.tsx | 9 ++++++--- src/components/Feed/ArticleCard/ArticleCard.tsx | 9 ++++++--- src/graphql/client/core.ts | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index f0d468a2..d22a8da7 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -43,8 +43,10 @@ export const Comment = (props: Props) => { const { showConfirm } = useConfirm() const { showSnackbar } = useSnackbar() - const canEdit = createMemo ( () => - Boolean(author()?.id) && ((props.comment?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.comment?.created_by?.id === author().id || session()?.user?.roles.includes('editor')), ) const comment = createMemo(() => props.comment) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 6e32755d..46177b8c 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -79,9 +79,12 @@ export const FullArticle = (props: Props) => { const formattedDate = createMemo(() => formatDate(new Date(props.article.published_at * 1000))) - const canEdit = createMemo(() => - Boolean(author()?.id) && ((props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id)) || - (props.article?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id) || + props.article?.created_by?.id === author().id || + session()?.user?.roles.includes('editor')), ) const mainTopic = createMemo(() => { diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index 451714da..c181cc27 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -120,9 +120,12 @@ export const ArticleCard = (props: ArticleCardProps) => { props.article.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '', ) - const canEdit = createMemo(() => - Boolean(author()?.id) && ((props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id)) || - (props.article?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id) || + props.article?.created_by?.id === author().id || + session()?.user?.roles.includes('editor')), ) const scrollToComments = (event) => { diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index e83d4872..752b4de4 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -184,9 +184,7 @@ export const apiClient = { return response.data.delete_reaction.reaction }, updateReaction: async (reaction: ReactionInput) => { - const response = await apiClient.private - .mutation(reactionUpdate, { reaction }) - .toPromise() + const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise() console.debug('[graphql.client.core] updateReaction:', response) return response.data.update_reaction.reaction }, From b731f1cfa66ff9ef098aa5ffd310f26dadf37b67 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 20:07:38 +0300 Subject: [PATCH 9/9] gql-fix --- src/graphql/mutation/core/reaction-update.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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