diff --git a/enshi/src/Components/ArticleViewer/VoteButton/VoteButton.tsx b/enshi/src/Components/ArticleViewer/VoteButton/VoteButton.tsx index 46a880b..18e7dcb 100644 --- a/enshi/src/Components/ArticleViewer/VoteButton/VoteButton.tsx +++ b/enshi/src/Components/ArticleViewer/VoteButton/VoteButton.tsx @@ -48,7 +48,7 @@ export default function VoteButton(props: TVoteButton) { queryKey: [props.vote + "voteCheck"], }); queryClient.invalidateQueries({ - queryKey: ["post_vote_counter"], + queryKey: [`post_vote_counter_${props.postId}`], }); }, }); diff --git a/enshi/src/Components/ArticleViewer/VoteCounter/VoteCounter.tsx b/enshi/src/Components/ArticleViewer/VoteCounter/VoteCounter.tsx index 4d54842..1115798 100644 --- a/enshi/src/Components/ArticleViewer/VoteCounter/VoteCounter.tsx +++ b/enshi/src/Components/ArticleViewer/VoteCounter/VoteCounter.tsx @@ -8,13 +8,14 @@ type TVoteCounter = { export default function VoteCounter(props: TVoteCounter) { const { data, isLoading } = useQuery({ - queryKey: ["post_vote_counter"], + queryKey: [`post_vote_counter_${props.postId}` ], queryFn: async () => { const response = await axiosLocalhost.get( `post-votes/${props.postId}` ); return response.data as { upvotes: number; downvotes: number }; }, + gcTime: 1000 * 60, }); const calculateRating = (upvotes: number, downvotes: number) => { @@ -22,12 +23,12 @@ export default function VoteCounter(props: TVoteCounter) { } if (isLoading) { - return + return {calculateRating(0, 0)} } - return + return {calculateRating(data?.upvotes || 0, data?.downvotes || 0)} ; }