From ef55c1ecd8ba486a658f50c41bdc3e60542e058f Mon Sep 17 00:00:00 2001 From: Samandar Turgunboyev Date: Fri, 20 Feb 2026 15:47:02 +0500 Subject: [PATCH] fixed --- src/app/[locale]/search/page.tsx | 4 +- src/features/profile/ui/History.tsx | 149 ++++++++++----------- src/features/profile/ui/Profile.tsx | 2 +- src/features/search/ui/Search.tsx | 50 +++---- src/widgets/categories/ui/product-card.tsx | 2 + src/widgets/navbar/ui/index.tsx | 2 +- 6 files changed, 105 insertions(+), 104 deletions(-) diff --git a/src/app/[locale]/search/page.tsx b/src/app/[locale]/search/page.tsx index 3e7b120..cd25fd4 100644 --- a/src/app/[locale]/search/page.tsx +++ b/src/app/[locale]/search/page.tsx @@ -36,7 +36,7 @@ export async function generateMetadata({ openGraph: { title, description, - url: `/search${query ? `?q=${encodeURIComponent(query)}` : ''}`, + url: `/search${query ? `?search=${encodeURIComponent(query)}` : ''}`, type: 'website', }, twitter: { @@ -64,7 +64,7 @@ export async function generateMetadata({ openGraph: { title, description, - url: `/search${query ? `?q=${encodeURIComponent(query)}` : ''}`, + url: `/search${query ? `?search=${encodeURIComponent(query)}` : ''}`, type: 'website', }, twitter: { diff --git a/src/features/profile/ui/History.tsx b/src/features/profile/ui/History.tsx index 943a999..48b93da 100644 --- a/src/features/profile/ui/History.tsx +++ b/src/features/profile/ui/History.tsx @@ -40,17 +40,20 @@ const HistoryTabs = () => { return (
- +
-

+

{t('Buyurtmalar topilmadi')}

-

+

{t( "Hali buyurtma qilmagansiz. Mahsulotlarni ko'rib chiqing va birinchi buyurtmangizni bering!", )}

- @@ -59,21 +62,21 @@ const HistoryTabs = () => { } return ( -
+
{/* Header */} -
+
-

+

{t('Buyurtmalar tarixi')}

-

+

{data.length} {t('ta buyurtma')}

{/* Orders List */} -
+
{data.map((order: OrderList) => { const totalPrice = order.items.reduce( (sum, item) => sum + Number(item.price) * item.quantity, @@ -83,31 +86,31 @@ const HistoryTabs = () => { return ( {/* Order Header */} -
-
-
-
+
+
+ {/* Order ID */} +
+
#{order.id}
-
-

- {t('Buyurtma raqami')} -

-
+

+ {t('Buyurtma raqami')} +

+ {/* Delivery date - compact on mobile */} {order.delivery_date && ( -
- +
+
-

+

{t('Yetkazib berish')}

-

+

{order.delivery_date}

@@ -117,14 +120,14 @@ const HistoryTabs = () => { {/* Comment */} {order.comment && ( -
+
- -
-

+ +

+

{t('Izoh')}:

-

+

{order.comment}

@@ -134,7 +137,7 @@ const HistoryTabs = () => {
{/* Products */} -
+
{order.items.map((item, index) => { const product = item.product; @@ -147,12 +150,12 @@ const HistoryTabs = () => { return (
-
- {/* Image */} +
+ {/* Image — smaller on mobile */}
-
+
{product.name} { {/* Info */}
-
-
-
- - {index + 1} - -

- {product.name} -

-
- - {product.short_name && ( -

- {product.short_name} -

- )} -
- -
-

- {t('Mahsulotlar narxi')} -

-

- {formatPrice(Number(item.price), true)} -

+ {/* Name row */} +
+
+ + {index + 1} + +

+ {product.name} +

+

+ {formatPrice(Number(item.price), true)} +

- {/* Details */} -
+ {product.short_name && ( +

+ {product.short_name} +

+ )} + + {/* Qty + Total — single row on mobile */} +
- + {t('Miqdor')} -

+ {item.quantity} -

+
-
- + {t('Jami')} -

+ {formatPrice( Number(item.price) * item.quantity, true, )} -

+
@@ -225,18 +220,18 @@ const HistoryTabs = () => {
{/* Footer */} -
-
-
+
+
+
{t('Mahsulotlar narxi')}: - + {formatPrice(totalPrice, true)}
-
+
{t('Mahsulotlar soni')}: - + {order.items.reduce( (sum, item) => sum + item.quantity, 0, @@ -246,8 +241,10 @@ const HistoryTabs = () => {
- {t('Umumiy summa')}: - + + {t('Umumiy summa')}: + + {formatPrice(totalPrice, true)}
@@ -258,7 +255,7 @@ const HistoryTabs = () => { onClick={() => router.push(`/profile/refresh-order?id=${order.id}`) } - className="w-full md:w-auto mt-3 gap-2" + className="w-full mt-3 gap-2 text-sm h-9" > {t('Qayta buyurtma')} diff --git a/src/features/profile/ui/Profile.tsx b/src/features/profile/ui/Profile.tsx index ea90984..8556001 100644 --- a/src/features/profile/ui/Profile.tsx +++ b/src/features/profile/ui/Profile.tsx @@ -129,7 +129,7 @@ const Profile = () => {
{/* Main Content */} -
+
diff --git a/src/features/search/ui/Search.tsx b/src/features/search/ui/Search.tsx index 49b757d..5493806 100644 --- a/src/features/search/ui/Search.tsx +++ b/src/features/search/ui/Search.tsx @@ -16,55 +16,57 @@ const SearchResult = () => { const t = useTranslations(); const searchParams = useSearchParams(); - const query = searchParams.get('q') || ''; + const query = searchParams.get('search') || ''; const [inputValue, setInputValue] = useState(query); - /* 🔹 Input va URL sync */ + /* 🔹 URL → Input sync */ useEffect(() => { setInputValue(query); }, [query]); + /* 🔹 Debounce → Input → URL sync */ + useEffect(() => { + const delay = setTimeout(() => { + if (!inputValue.trim()) { + router.replace('/search'); + } else { + router.replace(`/search?search=${encodeURIComponent(inputValue)}`); + } + }, 400); + + return () => clearTimeout(delay); + }, [inputValue, router]); + /* 🔹 Default product list */ const { data: productList, isLoading: listLoading } = useQuery({ queryKey: ['product_list'], queryFn: () => product_api.list({ page: 1, page_size: 12 }), select: (res) => res.data.results, enabled: !query, + staleTime: 0, }); /* 🔹 Search query */ const { data: searchList, isLoading: searchLoading } = useQuery({ - queryKey: ['search', query], + queryKey: ['search', query, inputValue], queryFn: () => product_api.search({ - search: query, + search: inputValue, // agar backend `q` kutsa → q: query page: 1, page_size: 12, }), - select: (res) => { - return res.data.products; - }, + select: (res) => res.data.products, enabled: !!query, + staleTime: 0, }); const data = query ? (searchList ?? []) : (productList ?? []); const isLoading = query ? searchLoading : listLoading; /* 🔹 Handlers */ - const handleSearch = (value: string) => { - setInputValue(value); - - if (!value.trim()) { - router.push('/search'); - return; - } - - router.push(`/search?q=${encodeURIComponent(value)}`); - }; - const clearSearch = () => { setInputValue(''); - router.push('/search'); + router.replace('/search'); }; return ( @@ -77,7 +79,7 @@ const SearchResult = () => { handleSearch(e.target.value)} + onChange={(e) => setInputValue(e.target.value)} className="w-full pl-10 pr-10 h-12" /> @@ -86,7 +88,7 @@ const SearchResult = () => { onClick={clearSearch} className="absolute right-3 top-1/2 -translate-y-1/2" > - + )}
@@ -97,10 +99,10 @@ const SearchResult = () => {
{t('Yuklanmoqda')}...
) : data.length > 0 ? (
- {data.map((products) => ( + {data.map((product) => ( ))}
diff --git a/src/widgets/categories/ui/product-card.tsx b/src/widgets/categories/ui/product-card.tsx index a6d2b38..f5615e0 100644 --- a/src/widgets/categories/ui/product-card.tsx +++ b/src/widgets/categories/ui/product-card.tsx @@ -196,6 +196,8 @@ export function ProductCard({ onSuccess: () => { queryClient.refetchQueries({ queryKey: ['product_list'] }); + queryClient.refetchQueries({ queryKey: ['list'] }); + queryClient.refetchQueries({ queryKey: ['all_products'] }); queryClient.refetchQueries({ queryKey: ['favourite_product'] }); }, diff --git a/src/widgets/navbar/ui/index.tsx b/src/widgets/navbar/ui/index.tsx index 2e11af3..a98404e 100644 --- a/src/widgets/navbar/ui/index.tsx +++ b/src/widgets/navbar/ui/index.tsx @@ -429,7 +429,7 @@ const Navbar = () => { onBlur={() => setTimeout(() => setSearchOpen(false), 200)} onKeyDown={(e) => { if (e.key === 'Enter' && query.trim()) { - router.push(`/search?q=${encodeURIComponent(query)}`); + router.push(`/search?search=${encodeURIComponent(query)}`); setSearchOpen(false); } }}