enh
This commit is contained in:
parent
a4218ee1ad
commit
c14e32522a
11 changed files with 42 additions and 24 deletions
|
|
@ -5,7 +5,7 @@ import { trpc } from '@/src/trpc-client';
|
|||
import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui';
|
||||
import { useRouter } from 'expo-router';
|
||||
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
|
||||
export default function FlashDeliveryBaseLayout() {
|
||||
const router = useRouter();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import BannerCarousel from "@/components/BannerCarousel";
|
|||
import { useUserDetails } from "@/src/contexts/AuthContext";
|
||||
import TabLayoutWrapper from "@/components/TabLayoutWrapper";
|
||||
import { useNavigationStore } from "@/src/store/navigationStore";
|
||||
import { useGetEssentialConsts } from "@/src/api-hooks/essential-consts.api";
|
||||
import { useGetEssentialConsts } from "@/src/hooks/prominent-api-hooks";
|
||||
import NextOrderGlimpse from "@/components/NextOrderGlimpse";
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { Image } from 'expo-image';
|
|||
import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui';
|
||||
import { MaterialIcons, Ionicons } from '@expo/vector-icons';
|
||||
import { trpc } from '@/src/trpc-client';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
import dayjs from 'dayjs';
|
||||
import { useRouter } from 'expo-router';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|||
import { View, ActivityIndicator, Platform } from 'react-native';
|
||||
import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui';
|
||||
import { trpc, trpcClient } from '@/src/trpc-client';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
import Constants from 'expo-constants';
|
||||
import * as Linking from 'expo-linking';
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import dayjs from 'dayjs';
|
|||
import { trpc } from '@/src/trpc-client';
|
||||
import { Image } from 'expo-image';
|
||||
import { orderStatusManipulator } from '@/src/lib/string-manipulators';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
|
||||
interface OrderItem {
|
||||
productName: string;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|||
import { View, ActivityIndicator } from 'react-native';
|
||||
import { WebView } from 'react-native-webview';
|
||||
import { trpc } from '@/src/trpc-client';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
import { theme, MyText, MyTouchableOpacity } from 'common-ui';
|
||||
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import dayjs from "dayjs";
|
|||
import { trpc } from "@/src/trpc-client";
|
||||
import { useAllProducts } from "@/src/hooks/prominent-api-hooks";
|
||||
import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
|
||||
interface CartPageProps {
|
||||
isFlashDelivery?: boolean;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute';
|
|||
import { trpc } from '@/src/trpc-client';
|
||||
import { useAllProducts } from '@/src/hooks/prominent-api-hooks';
|
||||
import { useGetCart } from '@/hooks/cart-query-hooks';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
import PaymentAndOrderComponent from '@/components/PaymentAndOrderComponent';
|
||||
import CheckoutAddressSelector from '@/components/CheckoutAddressSelector';
|
||||
import { useAddressStore } from '@/src/store/addressStore';
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
import { trpc } from '@/src/trpc-client';
|
||||
|
||||
export const useGetEssentialConsts = () => {
|
||||
const query = trpc.common.essentialConsts.useQuery(undefined, {
|
||||
refetchInterval: 60000,
|
||||
});
|
||||
return { ...query, refetch: query.refetch };
|
||||
};
|
||||
|
|
@ -7,7 +7,7 @@ import { useCartStore } from '@/src/store/cartStore';
|
|||
import { useFlashCartStore } from '@/src/store/flashCartStore';
|
||||
import { trpc } from '@/src/trpc-client';
|
||||
import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
|
||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||
import dayjs from 'dayjs';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,39 @@
|
|||
import { useQuery } from '@tanstack/react-query'
|
||||
import axios from 'axios'
|
||||
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'
|
||||
// import { AllProductsApiType } from '@backend/trpc/router'
|
||||
import { trpc } from '@/src/trpc-client'
|
||||
import { AllProductsApiType } from "@backend/trpc/router";
|
||||
// Local useGetEssentialConsts hook
|
||||
export const useGetEssentialConsts = () => {
|
||||
const query = trpc.common.essentialConsts.useQuery(undefined, {
|
||||
refetchInterval: 60000,
|
||||
})
|
||||
return { ...query, refetch: query.refetch }
|
||||
}
|
||||
|
||||
|
||||
type ProductsResponse = AllProductsApiType;
|
||||
// // Type definitions matching the backend response
|
||||
// interface ProductSummary {
|
||||
// id: number
|
||||
// name: string
|
||||
// shortDescription: string | null
|
||||
// price: number
|
||||
// marketPrice: number | null
|
||||
// unit: string
|
||||
// unitNotation: string
|
||||
// incrementStep: number
|
||||
// productQuantity: number
|
||||
// storeId: number | null
|
||||
// isOutOfStock: boolean
|
||||
// isFlashAvailable: boolean
|
||||
// nextDeliveryDate: string | null
|
||||
// images: string[]
|
||||
// }
|
||||
//
|
||||
// interface ProductsResponse {
|
||||
// products: ProductSummary[]
|
||||
// count: number
|
||||
// }
|
||||
//
|
||||
type ProductsResponse = AllProductsApiType;
|
||||
|
||||
export function useAllProducts() {
|
||||
const { data: essentialConsts } = useGetEssentialConsts()
|
||||
|
|
@ -16,15 +44,13 @@ export function useAllProducts() {
|
|||
const cacheUrl = assetsDomain && apiCacheKey
|
||||
? `${assetsDomain}${apiCacheKey}/products.json`
|
||||
: null
|
||||
|
||||
|
||||
return useQuery<ProductsResponse>({
|
||||
queryKey: ['all-products', cacheUrl],
|
||||
queryFn: async () => {
|
||||
if (!cacheUrl) {
|
||||
throw new Error('Cache URL not available')
|
||||
}
|
||||
console.log(cacheUrl)
|
||||
|
||||
const response = await axios.get<ProductsResponse>(cacheUrl)
|
||||
return response.data
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue