This commit is contained in:
Max 2025-01-29 13:50:54 +03:00
parent c816a4612c
commit 7475268eba
2 changed files with 5 additions and 4 deletions

View File

@ -48,7 +48,7 @@ export default function VoteButton(props: TVoteButton) {
queryKey: [props.vote + "voteCheck"], queryKey: [props.vote + "voteCheck"],
}); });
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: ["post_vote_counter"], queryKey: [`post_vote_counter_${props.postId}`],
}); });
}, },
}); });

View File

@ -8,13 +8,14 @@ type TVoteCounter = {
export default function VoteCounter(props: TVoteCounter) { export default function VoteCounter(props: TVoteCounter) {
const { data, isLoading } = useQuery({ const { data, isLoading } = useQuery({
queryKey: ["post_vote_counter"], queryKey: [`post_vote_counter_${props.postId}` ],
queryFn: async () => { queryFn: async () => {
const response = await axiosLocalhost.get( const response = await axiosLocalhost.get(
`post-votes/${props.postId}` `post-votes/${props.postId}`
); );
return response.data as { upvotes: number; downvotes: number }; return response.data as { upvotes: number; downvotes: number };
}, },
gcTime: 1000 * 60,
}); });
const calculateRating = (upvotes: number, downvotes: number) => { const calculateRating = (upvotes: number, downvotes: number) => {
@ -22,12 +23,12 @@ export default function VoteCounter(props: TVoteCounter) {
} }
if (isLoading) { if (isLoading) {
return <Skeleton> return <Skeleton className="w-4">
{calculateRating(0, 0)} {calculateRating(0, 0)}
</Skeleton> </Skeleton>
} }
return <Box> return <Box className="flex justify-center w-4 gap-2">
{calculateRating(data?.upvotes || 0, data?.downvotes || 0)} {calculateRating(data?.upvotes || 0, data?.downvotes || 0)}
</Box>; </Box>;
} }