From 364240c8dec8a4a2dc6fff7b4f10f8953360032a Mon Sep 17 00:00:00 2001 From: Mohammed Zafeeruddin <121102547+Zafeeruddin@users.noreply.github.com> Date: Sat, 5 Oct 2024 04:30:35 +0530 Subject: [PATCH] Fixed bugs of voting, editor clicks, replies (#1331) --- src/actions/commentVote/index.ts | 4 ++-- src/actions/commentVote/schema.ts | 1 + src/components/Sidebar.tsx | 3 +-- src/components/posts/PostCard.tsx | 19 ++++++++++++---- src/components/posts/form/form-vote.tsx | 30 ++++++++++++------------- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/actions/commentVote/index.ts b/src/actions/commentVote/index.ts index 53be3d0c3..069d38134 100644 --- a/src/actions/commentVote/index.ts +++ b/src/actions/commentVote/index.ts @@ -20,7 +20,7 @@ const voteHandler = async ( return { error: 'Unauthorized' }; } - const { questionId, answerId, commentId, voteType, currentPath } = data; + const { questionId, answerId, commentId, voteType, currentPath, slug } = data; if (!questionId && !answerId && !commentId) { return { error: 'No valid target specified.' }; @@ -142,7 +142,7 @@ const voteHandler = async ( } if (currentPath) { - revalidatePath(currentPath); + revalidatePath(`${currentPath}/${slug}`); } return { data: updatedEntity }; diff --git a/src/actions/commentVote/schema.ts b/src/actions/commentVote/schema.ts index 28cb1552a..9e1b6bb67 100644 --- a/src/actions/commentVote/schema.ts +++ b/src/actions/commentVote/schema.ts @@ -7,4 +7,5 @@ export const VoteHandleSchema = z.object({ answerId: z.number().optional(), voteType: z.nativeEnum(VoteType), currentPath: z.string(), + slug: z.string(), }); diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 61d7eac8e..d113df33b 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -206,8 +206,7 @@ export function Sidebar({ variants={sidebarVariants} className="fixed right-0 top-0 z-[99999] flex h-screen w-full flex-col gap-4 overflow-y-auto rounded-r-lg border-l border-primary/10 bg-neutral-50 dark:bg-neutral-900 md:max-w-[30vw]" > -
-

+

Course Content

{enableReply && ( -
+
= ({ sessionUser={sessionUser} reply={false} parentAuthorName={post.author.name} - isAnswer={true} - /> + isAnswer={true} />
))}

diff --git a/src/components/posts/form/form-vote.tsx b/src/components/posts/form/form-vote.tsx index 3663048c6..389266ae5 100644 --- a/src/components/posts/form/form-vote.tsx +++ b/src/components/posts/form/form-vote.tsx @@ -16,6 +16,7 @@ interface IVoteFormProps { upvotes: number; downvotes: number; votesArr: any[]; + slug: string; } const VoteForm: React.FC = ({ @@ -24,6 +25,7 @@ const VoteForm: React.FC = ({ upvotes = 0, downvotes = 0, votesArr, + slug, }) => { const currentPath = usePathname(); const { execute } = useAction(voteHandlerAction, { @@ -34,7 +36,7 @@ const VoteForm: React.FC = ({ }); const handleVote = (voteType: VoteType) => { toast.promise( - execute({ voteType, questionId, answerId, currentPath }), + execute({ voteType, questionId, answerId, currentPath, slug }), voteType === VoteType.DOWNVOTE ? { loading: 'Downvoting...', @@ -54,20 +56,19 @@ const VoteForm: React.FC = ({ return (
- { - e.preventDefault(); + onClick={(e) => { + e.stopPropagation(); handleVote(VoteType.UPVOTE); }} > - - -
+ + -
+
+ ); };