slide
This commit is contained in:
@@ -4,26 +4,25 @@ import { EmptyState } from "@/components/emptyState";
|
||||
import Text from "@/components/lib_components/text";
|
||||
import Title from "@/components/lib_components/title";
|
||||
import { LoadingSkeleton } from "@/components/loadingProduct";
|
||||
import { useCarType } from "@/store/carType";
|
||||
import { useSubCategory } from "@/store/subCategory";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const baseUrl = "https://api.spes-texnika.uz/api/v1/subcategory/?category=";
|
||||
|
||||
export default function CartType() {
|
||||
const initialCar = useCarType((state) => state.initialCar);
|
||||
const initialSubCategory = useSubCategory(
|
||||
(state) => state.initialSubCategory,
|
||||
);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const pathname = usePathname();
|
||||
const lang = pathname.split("/")[1];
|
||||
const [cars, setCars] = useState<any[]>([]);
|
||||
|
||||
console.log("car type id: ", initialCar.id);
|
||||
console.log("request URL: ", `${baseUrl}${initialCar.id}`);
|
||||
|
||||
useEffect(() => {
|
||||
// Agar ID bo'lmasa, fetchni ishga tushirma for gitea
|
||||
if (!initialCar.id) {
|
||||
if (!initialSubCategory.id) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +32,7 @@ export default function CartType() {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await fetch(`${baseUrl}${initialCar.id}`, {
|
||||
const response = await fetch(`${baseUrl}${initialSubCategory.id}`, {
|
||||
headers: {
|
||||
"Accept-Language": lang,
|
||||
},
|
||||
@@ -44,8 +43,7 @@ export default function CartType() {
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log("backend full response: ", result);
|
||||
console.log("backend Data: ", result?.data);
|
||||
console.log("inner car: ", result)
|
||||
|
||||
// Data array ekanligini tekshirish
|
||||
if (result?.data) {
|
||||
@@ -88,7 +86,6 @@ export default function CartType() {
|
||||
{loading ? (
|
||||
<LoadingSkeleton />
|
||||
) : cars.length > 0 ? (
|
||||
// MUHIM: Array ustidan map qilish kerak!
|
||||
cars.map((car, index) => (
|
||||
<InnerProductcard key={car.id || index} data={car} />
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user