Skip to content

Commit

Permalink
update bar refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
milad-alizadeh committed Dec 26, 2023
1 parent 29d3b78 commit 4fbf23f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
16 changes: 9 additions & 7 deletions src/app/(tabs)/my-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ export default function MyBarScreen() {
const { deleteFromMyBar, myBarRefetch, myBarLoading, sectionsData, sectionsHeader, myBarError } =
useFetchMyBar()

useEffect(() => {
if (isFocused) {
// Refetch the data when the tab gains focus
myBarRefetch()
}
}, [isFocused, myBarRefetch])

const {
getRecipeMatch,
partialMatchData,
Expand All @@ -58,6 +51,15 @@ export default function MyBarScreen() {
totalMatchError,
} = useFetchMatchedRecipes()

useEffect(() => {
if (isFocused) {
// Refetch the data when the tab gains focus
myBarRefetch()
totalMatchRefetch()
partialMatchRefetch()
}
}, [isFocused, myBarRefetch])

const renderIngredientItem = useCallback(
({ item }) => {
if (!item.name) return <View className="w-full h-64 bg-white p-page-spacing" />
Expand Down
11 changes: 0 additions & 11 deletions src/hooks/useFetchMatchedRecipes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useQuery } from '@apollo/client'
import { useIsFocused } from '@react-navigation/native'
import { router } from 'expo-router'
import { useEffect } from 'react'
import { GetPartialMatchRecipesQuery, GetTotalmatchRecipesQuery } from '~/__generated__/graphql'
import { CardProps } from '~/components'
import { GET_PARTIAL_MATCH_RECIPES, GET_TOTAL_MATCH_RECIPES } from '~/graphql/queries'
Expand All @@ -23,15 +21,6 @@ export const useFetchMatchedRecipes = () => {
error: partialMatchError,
} = useQuery(GET_PARTIAL_MATCH_RECIPES)

const isFocused = useIsFocused()

useEffect(() => {
if (isFocused) {
totalMatchRefetch()
partialMatchRefetch()
}
}, [isFocused, totalMatchRefetch, partialMatchRefetch])

const getRecipeMatch = (
matchedData: GetTotalmatchRecipesQuery | GetPartialMatchRecipesQuery,
): CardProps[] => {
Expand Down

0 comments on commit 4fbf23f

Please sign in to comment.