Skip to content

Commit

Permalink
fix: update tanstack query signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll committed Jan 17, 2025
1 parent 65a6cd2 commit d4023df
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
7 changes: 3 additions & 4 deletions src/frontend/pages/product/[productId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ const ProductDetail: NextPage = () => {
priceUsd = { units: 0, currencyCode: 'USD', nanos: 0 },
categories,
} = {} as Product,
} = useQuery(
['product', productId, 'selectedCurrency', selectedCurrency],
() => ApiGateway.getProduct(productId, selectedCurrency),
{
} = useQuery({
queryKey: ['product', productId, 'selectedCurrency', selectedCurrency],
queryFn: () => ApiGateway.getProduct(productId, selectedCurrency),
enabled: !!productId,
}
) as { data: Product };
Expand Down
24 changes: 10 additions & 14 deletions src/frontend/providers/Ad.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@ export const useAd = () => useContext(Context);

const AdProvider = ({ children, productIds, contextKeys }: IProps) => {
const { selectedCurrency } = useCurrency();
const { data: adList = [] } = useQuery(
['ads', contextKeys],
async () => {
const { data: adList = [] } = useQuery({
queryKey: ['ads', contextKeys],
queryFn: async () => {
if (contextKeys.length === 0) {
return [];
} else {
return ApiGateway.listAds(contextKeys);
}
},
{
refetchOnWindowFocus: false,
}
);
const { data: recommendedProductList = [] } = useQuery(
['recommendations', productIds, 'selectedCurrency', selectedCurrency],
() => ApiGateway.listRecommendations(productIds, selectedCurrency),
{
refetchOnWindowFocus: false,
}
);
refetchOnWindowFocus: false,
});
const { data: recommendedProductList = [] } = useQuery({
queryKey: ['recommendations', productIds, 'selectedCurrency', selectedCurrency],
queryFn: () => ApiGateway.listRecommendations(productIds, selectedCurrency),
refetchOnWindowFocus: false,
});

const value = useMemo(
() => ({
Expand Down
24 changes: 18 additions & 6 deletions src/frontend/providers/Cart.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ const CartProvider = ({ children }: IProps) => {
[queryClient]
);

const { data: cart = { userId: '', items: [] } } = useQuery(['cart', selectedCurrency], () =>
ApiGateway.getCart(selectedCurrency)
);
const addCartMutation = useMutation(ApiGateway.addCartItem, mutationOptions);
const emptyCartMutation = useMutation(ApiGateway.emptyCart, mutationOptions);
const placeOrderMutation = useMutation(ApiGateway.placeOrder, mutationOptions);
const { data: cart = { userId: '', items: [] } } = useQuery({
queryKey: ['cart', selectedCurrency],
queryFn: () => ApiGateway.getCart(selectedCurrency),
});
const addCartMutation = useMutation({
mutationFn: ApiGateway.addCartItem,
...mutationOptions,
});

const emptyCartMutation = useMutation({
mutationFn: ApiGateway.emptyCart,
...mutationOptions,
});

const placeOrderMutation = useMutation({
mutationFn: ApiGateway.placeOrder,
...mutationOptions,
});

const addItem = useCallback(
(item: CartItem) => addCartMutation.mutateAsync({ ...item, currencyCode: selectedCurrency }),
Expand Down

0 comments on commit d4023df

Please sign in to comment.