Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit e6b963d

Browse files
chore: don't fetch recipe votes data if it's not in view
1 parent 94b6733 commit e6b963d

File tree

1 file changed

+8
-2
lines changed
  • src/renderer/components/SearchResults

1 file changed

+8
-2
lines changed

src/renderer/components/SearchResults/Votes.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { useRef } from 'react';
2+
import { useInView } from 'framer-motion';
13
import { useMutation, useQuery } from '@apollo/client';
24
import { Flex, FlexProps, IconButton, Text, Tooltip } from '@chakra-ui/react';
35
import { DownVoteIcon, UpVoteIcon, useToast } from '@codiga/components';
6+
47
import { useUser } from '../UserContext';
58
import {
69
AddVoteMutationVariables,
@@ -28,8 +31,11 @@ const Votes = ({
2831
const toast = useToast();
2932
const { id: userId } = useUser();
3033

34+
const ref = useRef(null);
35+
const isInView = useInView(ref);
36+
3137
const { data, refetch } = useQuery(GET_RECIPE_VOTES_QUERY, {
32-
skip: !userId,
38+
skip: !userId || !isInView,
3339
variables: {
3440
recipeId: entityId,
3541
},
@@ -89,7 +95,7 @@ const Votes = ({
8995
const countColor = isUpVoted || isDownVoted ? 'rose.50' : undefined;
9096

9197
return (
92-
<Flex gridGap="space_4" alignItems="center" {...props}>
98+
<Flex ref={ref} gridGap="space_4" alignItems="center" {...props}>
9399
<Tooltip
94100
label="Please log in to upvote"
95101
shouldWrapChildren

0 commit comments

Comments
 (0)