Skip to content

Commit 3f1ff1a

Browse files
authored
productsPageDone (#37)
* productsPageDone
1 parent 29c40c1 commit 3f1ff1a

File tree

8 files changed

+122
-47
lines changed

8 files changed

+122
-47
lines changed
33 KB
Loading
48.6 KB
Loading
42.6 KB
Loading
28.7 KB
Loading
252 KB
Loading

src/components/Product.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { useState } from 'react';
2+
import { products, ProductType } from '@/constants/ProductsData';
3+
4+
const Product = () => {
5+
return (
6+
<section className="py-12 px-4">
7+
<div className="max-w-5xl mx-auto grid grid-cols-1 gap-12">
8+
{products.map((product, index) => (
9+
<ProductCard key={index} product={product} />
10+
))}
11+
</div>
12+
</section>
13+
);
14+
};
15+
16+
const ProductCard = ({ product }: { product: ProductType }) => {
17+
const imageUrls = Object.values(product.colors); // Get all image URLs
18+
const hasMultipleImages = imageUrls.length > 1; // Check if there are multiple images
19+
const [currentImageIndex, setCurrentImageIndex] = useState(0);
20+
21+
const nextImage = () => {
22+
setCurrentImageIndex((prevIndex) => (prevIndex + 1) % imageUrls.length);
23+
};
24+
25+
const prevImage = () => {
26+
setCurrentImageIndex((prevIndex) =>
27+
prevIndex === 0 ? imageUrls.length - 1 : prevIndex - 1,
28+
);
29+
};
30+
31+
return (
32+
<div className="grid grid-cols-1 md:grid-cols-2 gap-8 border-b pb-10">
33+
{/* Product Image / Carousel */}
34+
<div className="relative">
35+
<img
36+
src={imageUrls[currentImageIndex]}
37+
alt={product.name}
38+
className="w-full rounded-lg shadow-md"
39+
/>
40+
41+
{/* Image Carousel Controls (only if multiple images exist) */}
42+
{hasMultipleImages && (
43+
<>
44+
<button
45+
onClick={prevImage}
46+
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-black bg-opacity-50 text-white px-3 py-2 rounded-full"
47+
>
48+
49+
</button>
50+
<button
51+
onClick={nextImage}
52+
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-black bg-opacity-50 text-white px-3 py-2 rounded-full"
53+
>
54+
55+
</button>
56+
</>
57+
)}
58+
</div>
59+
60+
{/* Product Details */}
61+
<div>
62+
<h3 className="text-3xl font-semibold">{product.name}</h3>
63+
<p className="text-gray-600 mt-2">{product.description}</p>
64+
65+
{/* Buy Now Button (Links to an external page) */}
66+
<div className="mt-6">
67+
<a
68+
href={product.link}
69+
target="_blank"
70+
rel="noopener noreferrer"
71+
className="bg-blue-600 text-white px-6 py-3 rounded-lg text-lg shadow-md hover:bg-blue-700 transition"
72+
>
73+
Buy Now
74+
</a>
75+
</div>
76+
</div>
77+
</div>
78+
);
79+
};
80+
81+
export default Product;

src/constants/ProductsData.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export type ProductType = {
2+
name: string;
3+
description: string;
4+
colors: Record<string, string>; // Image URLs mapped by color names
5+
link: string; // External purchase link
6+
};
7+
8+
export const products: ProductType[] = [
9+
{
10+
name: 'Classic Cotton T-Shirt',
11+
description:
12+
'Support Sugar Labs®—a US-based 501(c)(3) nonprofit empowering youth through technology education—with this premium cotton t-shirt, designed for comfort and durability.',
13+
colors: {
14+
blue: 'assets/Products/sugarTshirtBlue.jpeg',
15+
white: 'assets/Products/sugarTshirtWhite.jpeg',
16+
green: 'assets/Products/sugarTshirtGreen.jpeg',
17+
purple: 'assets/Products/sugarTshirtPurple.jpeg',
18+
},
19+
link: 'https://www.bonfire.com/store/sugar-labs-merch/', // Purchase link
20+
},
21+
{
22+
name: 'SugarLabs USB',
23+
description:
24+
'Easily install Fedora Sugar On A Stick (SOAS) to your device directly from this USB flash drive. The Fedora SOAS on this USB drive is for Intel and AMD x86_64 systems.',
25+
colors: {
26+
white: 'assets/Products/sugarlabsUsb.jpeg',
27+
},
28+
link: 'https://www.usbmemorydirect.com/store/novelty/sugarlabs/', // Purchase link
29+
},
30+
];

src/pages/Products.tsx

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,23 @@
11
import Header from '@/sections/Header';
22
import Footer from '@/sections/Footer';
3+
import Product from '@/components/Product';
34

4-
const Products = () => {
5+
const ProductsPage = () => {
56
return (
67
<div>
78
<Header />
8-
<main className="container mx-auto p-4">
9-
<h1 className="text-4xl font-bold text-center my-8">Products</h1>
10-
<p className="text-lg text-gray-700 text-center">
11-
Explore our range of products designed to enhance learning and
12-
education.
13-
</p>
14-
<div className="mt-8 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
15-
<div className="bg-blue-100 p-6 rounded-lg shadow-md">
16-
<h2 className="text-2xl font-semibold">Sugar Desktop</h2>
17-
<p className="mt-2 text-gray-700">
18-
A free and open-source desktop environment for learning.
19-
</p>
20-
<a
21-
href="#"
22-
className="mt-4 inline-block text-blue-600 hover:underline"
23-
>
24-
Learn More →
25-
</a>
26-
</div>
27-
<div className="bg-green-100 p-6 rounded-lg shadow-md">
28-
<h2 className="text-2xl font-semibold">Sugar Learning Platform</h2>
29-
<p className="mt-2 text-gray-700">
30-
A web-based platform for learning and collaboration.
31-
</p>
32-
<a
33-
href="#"
34-
className="mt-4 inline-block text-green-600 hover:underline"
35-
>
36-
Learn More →
37-
</a>
38-
</div>
39-
<div className="bg-yellow-100 p-6 rounded-lg shadow-md">
40-
<h2 className="text-2xl font-semibold">Sugar Activities</h2>
41-
<p className="mt-2 text-gray-700">
42-
A collection of educational activities for Sugar Desktop and the
43-
Sugar Learning Platform.
44-
</p>
45-
<a
46-
href="#"
47-
className="mt-4 inline-block text-yellow-600 hover:underline"
48-
>
49-
Learn More →
50-
</a>
51-
</div>
52-
</div>
9+
<main className="container mx-auto px-4 sm:px-6 md:px-8 py-6">
10+
{/* Responsive Heading */}
11+
<h2 className="text-6xl sm:text-7xl md:text-8xl lg:text-9xl font-extralight text-center mb-6 font-[Oswald] tracking-wide py-8">
12+
<span className="text-black">OUR</span>{' '}
13+
<span className="text-orange-500">PRODUCTS</span>
14+
</h2>
15+
16+
<Product />
5317
</main>
5418
<Footer />
5519
</div>
5620
);
5721
};
5822

59-
export default Products;
23+
export default ProductsPage;

0 commit comments

Comments
 (0)