diff --git a/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx b/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx index e497a705..28f6a224 100644 --- a/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx +++ b/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx @@ -1,4 +1,5 @@ import clsx from 'clsx'; +import type { Dispatch, SetStateAction } from 'react'; import { useState } from 'react'; import type { SubmitHandler } from 'react-hook-form'; import { useForm } from 'react-hook-form'; @@ -8,7 +9,7 @@ import { } from '@heroicons/react/20/solid'; import { FaceSmileIcon } from '@heroicons/react/24/outline'; import { Vote } from '@prisma/client'; -import { Button, Spinner, TextArea } from '@tih/ui'; +import { Button, TextArea } from '@tih/ui'; import { trpc } from '~/utils/trpc'; @@ -32,6 +33,9 @@ export default function ResumeCommentListItem({ const isCommentOwner = userId === comment.user.userId; const [isEditingComment, setIsEditingComment] = useState(false); + const [upvoteAnimation, setUpvoteAnimation] = useState(false); + const [downvoteAnimation, setDownvoteAnimation] = useState(false); + const { register, handleSubmit, @@ -104,16 +108,31 @@ export default function ResumeCommentListItem({ setValue('description', value.trim(), { shouldDirty: true }); }; - const onVote = async (value: Vote) => { + const onVote = async ( + value: Vote, + setAnimation: Dispatch>, + ) => { + setAnimation(true); + if (commentVotesQuery.data?.userVote?.value === value) { - return commentVotesDeleteMutation.mutate({ - commentId: comment.id, - }); + return commentVotesDeleteMutation.mutate( + { + commentId: comment.id, + }, + { + onSettled: async () => setAnimation(false), + }, + ); } - return commentVotesUpsertMutation.mutate({ - commentId: comment.id, - value, - }); + return commentVotesUpsertMutation.mutate( + { + commentId: comment.id, + value, + }, + { + onSettled: async () => setAnimation(false), + }, + ); }; return ( @@ -201,20 +220,28 @@ export default function ResumeCommentListItem({ commentVotesDeleteMutation.isLoading } type="button" - onClick={() => onVote(Vote.UPVOTE)}> + onClick={() => onVote(Vote.UPVOTE, setUpvoteAnimation)}> +
{commentVotesQuery.data?.numVotes ?? 0}
+ @@ -243,12 +276,6 @@ export default function ResumeCommentListItem({ Edit )} - - {(commentVotesQuery.isLoading || - commentVotesUpsertMutation.isLoading || - commentVotesDeleteMutation.isLoading) && ( - - )}