diff --git a/src/App.tsx b/src/App.tsx index fada790..c1dbc20 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,11 +9,14 @@ function App() { <> - - } /> - } /> - } /> - + + {/* Set ProductList as the default page */} + }> + } /> + {/* Route to ProductPage with a dynamic product ID */} + } /> + + diff --git a/src/pages/Product.tsx b/src/pages/Product.tsx index 81c2e59..6eb1b07 100644 --- a/src/pages/Product.tsx +++ b/src/pages/Product.tsx @@ -1,21 +1,34 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import { lazy, Suspense, useState } from "react"; +import { lazy, Suspense, useState, useEffect } from "react"; +import { useParams } from "react-router-dom"; import { ShoppingBagIcon, UserIcon } from "@heroicons/react/24/outline"; import ColorPicker from "../components/ColorPicker"; -import FilamentDropdown from '../components/FilamentDropdown'; +import FilamentDropdown from "../components/FilamentDropdown"; const PreviewComponent = lazy(() => import("../components/PreviewComponent")); -const product = { - name: "RC Wheels", - price: "$35", - description: ` -

This is a 12mm RC buggy wheel that will fit any modern buggy for 1/10 scale racing.

- `, -}; - export default function ProductPage() { - const [selectedFilament, setSelectedFilament] = useState("PLA"); + const { id } = useParams<{ id: string }>(); + const [product, setProduct] = useState(null); + const [selectedFilament, setSelectedFilament] = useState("PLA"); + + // Fetch product data based on ID + useEffect(() => { + const fetchProduct = async () => { + try { + const response = await fetch(`https://3dprinter-web-api.benhalverson.workers.dev/product/${id}`); + const data = await response.json(); + setProduct(data); + console.log('data', data); + } catch (error) { + console.error("Error fetching product:", error); + } + }; + + if (id) fetchProduct(); + }, [id]); + + if (!product) return
Loading product...
; return (
@@ -79,8 +92,9 @@ export default function ProductPage() {
Loading...
}> + false} onError={() => (
@@ -100,8 +114,7 @@ export default function ProductPage() {

Color

- - +