diff --git a/components/productSection/ProductsGrid.tsx b/components/productSection/ProductsGrid.tsx index f4b0403..d74e421 100644 --- a/components/productSection/ProductsGrid.tsx +++ b/components/productSection/ProductsGrid.tsx @@ -61,11 +61,14 @@ export function ProductsGrid() {
- {loading &&
-
} + {loading && ( +
+ +
+ )} {/* Product Grid */} - { loading|| allProducts && allProducts.length > 0 ? ( + {loading || (allProducts && allProducts.length > 0) ? ( {allProducts.map((product: any) => ( - + ))} diff --git a/components/productsPage/products.tsx b/components/productsPage/products.tsx index 89ab8bc..2235bcc 100644 --- a/components/productsPage/products.tsx +++ b/components/productsPage/products.tsx @@ -1,10 +1,10 @@ "use client"; import { useEffect, useState } from "react"; import EmptyState from "./emptyData"; -import { ProductModal } from "../productSection/ProductModal"; import { motion } from "framer-motion"; import { ProductCard } from "../productSection/ProductCard"; import axios from "axios"; +import Loading from "../loading"; const itemVariants = { hidden: { opacity: 0, y: 20 }, @@ -12,49 +12,42 @@ const itemVariants = { }; export default function Products() { - const [allProducts, setAllProducts] = useState(null); - const [selectedProduct, setSelectedProduct] = useState(null); + const [allProducts, setAllProducts] = useState([]); + const [loading, setLoading] = useState(false); useEffect(() => { async function getData() { - await axios.get("https://admin.promtechno.uz/api/products/").then((res) => { - console.log("all data: ", res?.data); - const allData = res?.data || []; - setAllProducts(allData); - }); + setLoading(true); + await axios + .get("https://admin.promtechno.uz/api/products/") + .then((res) => { + console.log("all data: ", res?.data); + const allData = res?.data || []; + setAllProducts(allData); + setLoading(false); + }); } getData(); }, []); - const handleViewDetails = (id: number) => { - const product = allProducts.find((p: any) => p.id === id); - if (product) { - setSelectedProduct(product); - } - }; return (
- {allProducts && allProducts.length > 0 ? ( + {loading && ( +
+ +
+ )} + {loading || (allProducts && allProducts.length > 0) ? (
{allProducts.map((product: any) => ( - + ))}
) : ( )} - {/* Product Modal */} - {selectedProduct && ( - setSelectedProduct(null)} - /> - )}
); }