Skip to content

Commit

Permalink
update my bar
Browse files Browse the repository at this point in the history
  • Loading branch information
milad-alizadeh committed Dec 20, 2023
1 parent 3f0669f commit b19cb5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/app/(tabs)/my-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ export default function MyBarScreen() {
deleteFromMyBar,
getRecipeMatch,
ingredientRefetch,
ingredientLoading,
myBarRefetch,
myBarLoading,
partialMatchData,
partialMatchRefetch,
sectionsData,
sectionsHeader,
totalMatchData,
totalMatchLoading,
totalMatchRefetch,
ingredientError,
myBarError,
totalMatchError,
} = useFetchMatchedRecipes()

Expand Down Expand Up @@ -76,6 +77,7 @@ export default function MyBarScreen() {
onCompleted: () => {
capture('my_bar:ingredient_remove', { ingredient_name: item.name })
ingredientRefetch()
myBarRefetch()
totalMatchRefetch()
partialMatchRefetch()
setDeleteingItemId('')
Expand Down Expand Up @@ -159,12 +161,12 @@ export default function MyBarScreen() {
ListFooterComponent={<View />}
ListEmptyComponent={
<View className="flex-1 justify-center w-full">
{!!ingredientError && (
{!!myBarError && (
<View className="p-6">
<InfoBox type="error" description={ingredientError?.message} />
<InfoBox type="error" description={myBarError?.message} />
</View>
)}
{ingredientLoading ? (
{myBarLoading ? (
<ActivityIndicator />
) : (
<View
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useFetchIngredients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ export const useFetchIngredients = () => {
fetchPolicy: 'cache-and-network',
})

const { data: selectedIngredients } = useQuery(GET_INGREDIENTS_IN_MY_BAR, {
fetchPolicy: 'cache-and-network',
})
const { data: selectedIngredients } = useQuery(GET_INGREDIENTS_IN_MY_BAR)

useEffect(() => {
if (!categories) return
Expand Down
28 changes: 18 additions & 10 deletions src/hooks/useFetchMatchedRecipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { useEffect } from 'react'
import { GetPartialMatchRecipesQuery, GetTotalmatchRecipesQuery } from '~/__generated__/graphql'
import { CardProps, SectionDataType, SectionHeaderType } from '~/components'
import { DELETE_FROM_MY_BAR } from '~/graphql/mutations/deleteFromMyBar'
import { GET_MY_BAR, GET_PARTIAL_MATCH_RECIPES, GET_TOTAL_MATCH_RECIPES } from '~/graphql/queries'
import {
GET_INGREDIENTS_IN_MY_BAR,
GET_MY_BAR,
GET_PARTIAL_MATCH_RECIPES,
GET_TOTAL_MATCH_RECIPES,
} from '~/graphql/queries'
import { useAppContent } from '~/providers'
import { captureError } from '~/utils/captureError'

Expand All @@ -14,11 +19,13 @@ export const useFetchMatchedRecipes = () => {
const { my_bar } = useAppContent()
const {
data: myBarData,
loading: ingredientLoading,
refetch: ingredientRefetch,
error: ingredientError,
loading: myBarLoading,
refetch: myBarRefetch,
error: myBarError,
} = useQuery(GET_MY_BAR)

const { refetch: ingredientRefetch } = useQuery(GET_INGREDIENTS_IN_MY_BAR)

const {
data: totalMatchData,
refetch: totalMatchRefetch,
Expand All @@ -38,11 +45,11 @@ export const useFetchMatchedRecipes = () => {
useEffect(() => {
if (isFocused) {
// Refetch the data when the tab gains focus
ingredientRefetch()
myBarRefetch()
totalMatchRefetch()
partialMatchRefetch()
}
}, [isFocused, ingredientRefetch, totalMatchRefetch, partialMatchRefetch])
}, [isFocused, myBarRefetch, totalMatchRefetch, partialMatchRefetch])

const getRecipeMatch = (
matchedData: GetTotalmatchRecipesQuery | GetPartialMatchRecipesQuery,
Expand Down Expand Up @@ -81,19 +88,20 @@ export const useFetchMatchedRecipes = () => {
return {
deleteFromMyBar,
getRecipeMatch,
ingredientLoading,
ingredientRefetch,
myBarError,
myBarLoading,
myBarRefetch,
partialMatchData,
partialMatchError,
partialMatchLoading,
partialMatchRefetch,
sectionsData,
sectionsHeader,
totalMatchData,
totalMatchError,
totalMatchLoading,
totalMatchRefetch,
ingredientError,
totalMatchError,
partialMatchError,
}
} catch (error) {
captureError(error)
Expand Down

0 comments on commit b19cb5c

Please sign in to comment.