This commit is contained in:
shafi54 2026-03-10 13:05:33 +05:30
parent a4218ee1ad
commit c14e32522a
11 changed files with 42 additions and 24 deletions

View file

@ -5,7 +5,7 @@ import { trpc } from '@/src/trpc-client';
import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui'; import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; 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() { export default function FlashDeliveryBaseLayout() {
const router = useRouter(); const router = useRouter();

View file

@ -28,7 +28,7 @@ import BannerCarousel from "@/components/BannerCarousel";
import { useUserDetails } from "@/src/contexts/AuthContext"; import { useUserDetails } from "@/src/contexts/AuthContext";
import TabLayoutWrapper from "@/components/TabLayoutWrapper"; import TabLayoutWrapper from "@/components/TabLayoutWrapper";
import { useNavigationStore } from "@/src/store/navigationStore"; 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"; import NextOrderGlimpse from "@/components/NextOrderGlimpse";
dayjs.extend(relativeTime); dayjs.extend(relativeTime);

View file

@ -4,7 +4,7 @@ import { Image } from 'expo-image';
import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui'; import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui';
import { MaterialIcons, Ionicons } from '@expo/vector-icons'; import { MaterialIcons, Ionicons } from '@expo/vector-icons';
import { trpc } from '@/src/trpc-client'; 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 dayjs from 'dayjs';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';

View file

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { View, ActivityIndicator, Platform } from 'react-native'; import { View, ActivityIndicator, Platform } from 'react-native';
import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui'; import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui';
import { trpc, trpcClient } from '@/src/trpc-client'; 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 Constants from 'expo-constants';
import * as Linking from 'expo-linking'; import * as Linking from 'expo-linking';

View file

@ -8,7 +8,7 @@ import dayjs from 'dayjs';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { Image } from 'expo-image'; import { Image } from 'expo-image';
import { orderStatusManipulator } from '@/src/lib/string-manipulators'; 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 { interface OrderItem {
productName: string; productName: string;

View file

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { View, ActivityIndicator } from 'react-native'; import { View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview'; import { WebView } from 'react-native-webview';
import { trpc } from '@/src/trpc-client'; 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 { theme, MyText, MyTouchableOpacity } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';

View file

@ -26,7 +26,7 @@ import dayjs from "dayjs";
import { trpc } from "@/src/trpc-client"; import { trpc } from "@/src/trpc-client";
import { useAllProducts } from "@/src/hooks/prominent-api-hooks"; import { useAllProducts } from "@/src/hooks/prominent-api-hooks";
import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-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 { interface CartPageProps {
isFlashDelivery?: boolean; isFlashDelivery?: boolean;

View file

@ -10,7 +10,7 @@ import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useAllProducts } from '@/src/hooks/prominent-api-hooks'; import { useAllProducts } from '@/src/hooks/prominent-api-hooks';
import { useGetCart } from '@/hooks/cart-query-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 PaymentAndOrderComponent from '@/components/PaymentAndOrderComponent';
import CheckoutAddressSelector from '@/components/CheckoutAddressSelector'; import CheckoutAddressSelector from '@/components/CheckoutAddressSelector';
import { useAddressStore } from '@/src/store/addressStore'; import { useAddressStore } from '@/src/store/addressStore';

View file

@ -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 };
};

View file

@ -7,7 +7,7 @@ import { useCartStore } from '@/src/store/cartStore';
import { useFlashCartStore } from '@/src/store/flashCartStore'; import { useFlashCartStore } from '@/src/store/flashCartStore';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; 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 dayjs from 'dayjs';
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';

View file

@ -1,11 +1,39 @@
import { useQuery } from '@tanstack/react-query' import { useQuery } from '@tanstack/react-query'
import axios from 'axios' import axios from 'axios'
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api' import { trpc } from '@/src/trpc-client'
// import { AllProductsApiType } from '@backend/trpc/router'
import { AllProductsApiType } from "@backend/trpc/router"; 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 definitions matching the backend response
type ProductsResponse = AllProductsApiType; // 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() { export function useAllProducts() {
const { data: essentialConsts } = useGetEssentialConsts() const { data: essentialConsts } = useGetEssentialConsts()
@ -16,15 +44,13 @@ export function useAllProducts() {
const cacheUrl = assetsDomain && apiCacheKey const cacheUrl = assetsDomain && apiCacheKey
? `${assetsDomain}${apiCacheKey}/products.json` ? `${assetsDomain}${apiCacheKey}/products.json`
: null : null
return useQuery<ProductsResponse>({ return useQuery<ProductsResponse>({
queryKey: ['all-products', cacheUrl], queryKey: ['all-products', cacheUrl],
queryFn: async () => { queryFn: async () => {
if (!cacheUrl) { if (!cacheUrl) {
throw new Error('Cache URL not available') throw new Error('Cache URL not available')
} }
console.log(cacheUrl)
const response = await axios.get<ProductsResponse>(cacheUrl) const response = await axios.get<ProductsResponse>(cacheUrl)
return response.data return response.data
}, },