diff --git a/src/Components/HOC/SearchWithDrawer.tsx b/src/Components/HOC/SearchWithDrawer.tsx index 03db1bd..f3ae48e 100644 --- a/src/Components/HOC/SearchWithDrawer.tsx +++ b/src/Components/HOC/SearchWithDrawer.tsx @@ -9,8 +9,7 @@ import Empty from '../Utils/Search/Empty'; const SearchWithDrawer = () => { const [open, setOpen] = useState(false); const [placement, setPlacement] = useState('right'); - const [noDataFound, setNoDataFound] = useState(true); - console.log(noDataFound); + const [noDataFound, setNoDataFound] = useState(false); return ( <> @@ -35,7 +34,7 @@ const SearchWithDrawer = () => { setOpen(false)}>
- {noDataFound && } + {noDataFound ? :"" }
diff --git a/src/Components/Utils/Search/SearchButton.tsx b/src/Components/Utils/Search/SearchButton.tsx index 4dbbe4b..aab6073 100644 --- a/src/Components/Utils/Search/SearchButton.tsx +++ b/src/Components/Utils/Search/SearchButton.tsx @@ -1,10 +1,11 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import { Select, Spin } from 'antd'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { LuSearch } from 'react-icons/lu'; import { useGetBaseProduct } from '../../../api/baseProduct'; import { Product } from '../../../types/item'; +import _ from 'lodash'; interface SearchButtonProps { setOpen: (open: boolean) => void; @@ -16,26 +17,36 @@ const SearchButton: React.FC = ({ setOpen, setNoDataFound }) const { t } = useTranslation(); const [searchParams] = useSearchParams(); const [query, setQuery] = useState(searchParams.get('search')); - + const { data, isLoading } = useGetBaseProduct({ - name: query, + search: query, }); + console.log(query ,"query"); + const BaseProducts = (data?.products as Product[]) || []; - + useEffect(() => { - setNoDataFound(!isLoading && BaseProducts.length <= 0); + setNoDataFound(!isLoading && BaseProducts.length < 1); }, [isLoading, BaseProducts, setNoDataFound]); const options = BaseProducts.map((product: any) => ({ value: product.base_product_id, label: product?.name as string, })); + console.log(BaseProducts?.length, "base_products"); + + const debouncedSearchChange = useCallback( + _.debounce((value: string) => { + setQuery(value); + navigate(`${window.location.pathname}?search=${value}`, { + replace: true, + }); + }, 500), // Adjust the debounce delay (in milliseconds) as needed + [] + ); - const handleSearchChange = (value: string) => { - setQuery(value); - navigate(`${window.location.pathname}?search=${value}`, { - replace: true, - }); + const handleSearchChange = (value: string) => { + debouncedSearchChange(value); }; const handleSelectChange = (value: number) => { diff --git a/src/Components/Utils/SearchBar/SearchBar.scss b/src/Components/Utils/SearchBar/SearchBar.scss index 1966e7e..8d34ec3 100755 --- a/src/Components/Utils/SearchBar/SearchBar.scss +++ b/src/Components/Utils/SearchBar/SearchBar.scss @@ -99,6 +99,9 @@ @include Flex; .Empty{ @include Flex; flex-direction: column; + p,h1{ + font-size: 20px; + } } } .ViewSearch{ @@ -114,4 +117,16 @@ .search_comp{ display: flex; flex-direction: column; +} + + +@media screen and (max-width:600px) { + .not_found_section{ + .Empty{ + h1 , p{ + text-align: center; + font-size: 12px !important; + } + } + } } \ No newline at end of file diff --git a/src/api/helper/useGetQuery.ts b/src/api/helper/useGetQuery.ts index 34af910..4ebd349 100644 --- a/src/api/helper/useGetQuery.ts +++ b/src/api/helper/useGetQuery.ts @@ -34,6 +34,7 @@ function useGetQuery( return response?.data ?? []; }, options, + ); } diff --git a/src/lib/ReactQueryProvider.tsx b/src/lib/ReactQueryProvider.tsx index fa16858..3ed03b7 100755 --- a/src/lib/ReactQueryProvider.tsx +++ b/src/lib/ReactQueryProvider.tsx @@ -2,7 +2,13 @@ import React from "react"; import { QueryClient, QueryClientProvider } from "react-query"; function QueryProvider({ children }: any) { - const queryClient = new QueryClient(); + const queryClient = new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus:false, + }, + }, + }); return ( {children} diff --git a/src/translate/ar.json b/src/translate/ar.json index e43a464..42d127e 100755 --- a/src/translate/ar.json +++ b/src/translate/ar.json @@ -388,6 +388,8 @@ "sub_categories": "الفئات الفرعية", "Clear_All": "مسح الكل", "Track, return or purchase items":"تتبع أو إرجاع أو شراء العناصر", -"Order History":"تاريخ الطلب" +"Order History":"تاريخ الطلب", +"Please try using other keywords to find the product name":"يرجى محاولة استخدام كلمات رئيسية أخرى للعثور على اسم المنتج", +"There are no suitable products":"لا توجد منتجات مناسبة" } \ No newline at end of file diff --git a/src/translate/ch.json b/src/translate/ch.json index fcbc5a5..1b39c00 100644 --- a/src/translate/ch.json +++ b/src/translate/ch.json @@ -374,5 +374,7 @@ "sub_categories": "子类别", "Clear_All": "清除所有", "Track, return or purchase items":"跟踪、退货或购买物品", - "Order History":"订单历史" + "Order History":"订单历史", + "Please try using other keywords to find the product name":"请尝试使用其他关键字来查找产品名称", + "There are no suitable products":"没有合适的产品" } \ No newline at end of file diff --git a/src/translate/en.json b/src/translate/en.json index f2ebab7..fb32c19 100755 --- a/src/translate/en.json +++ b/src/translate/en.json @@ -385,7 +385,9 @@ "sub_categories": "sub categories", "Clear_All": "Clear All", "Track, return or purchase items":"Track, return or purchase items", - "Order History":"Order History" + "Order History":"Order History", + "Please try using other keywords to find the product name":"Please try using other keywords to find the product name", + "There are no suitable products":"There are no suitable products" } \ No newline at end of file