mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
Merge branch 'develop' of ssh://gitea.gofwd.group:2225/dstrawsb/ballistic-builder into develop
This commit is contained in:
@@ -14,8 +14,8 @@ const geistMono = localFont({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Create Next App",
|
title: "Ballistic Builder",
|
||||||
description: "Generated by create next app",
|
description: "Freedom On",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default function Home() {
|
|||||||
{/* Header Section */}
|
{/* Header Section */}
|
||||||
<header className="bg-gray-800 text-white py-4 shadow-md">
|
<header className="bg-gray-800 text-white py-4 shadow-md">
|
||||||
<div className="container mx-auto px-6 flex justify-between items-center">
|
<div className="container mx-auto px-6 flex justify-between items-center">
|
||||||
<h1 className="text-2xl font-bold">Firearm Builder</h1>
|
<h1 className="text-2xl font-bold">Ballistic Builder</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ul className="flex space-x-4">
|
<ul className="flex space-x-4">
|
||||||
<li><Link href="#features" className="hover:underline">Features</Link></li>
|
<li><Link href="#features" className="hover:underline">Features</Link></li>
|
||||||
|
|||||||
109
pages/builder.js
109
pages/builder.js
@@ -1,54 +1,85 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
export default function Builder() {
|
export default function Builder() {
|
||||||
const [build, setBuild] = useState([]);
|
const [products, setProducts] = useState([]); // Available products from the API
|
||||||
const [part, setPart] = useState("");
|
const [build, setBuild] = useState([]); // User's selected parts
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const addPartToBuild = () => {
|
// Fetch available products on page load
|
||||||
if (part) {
|
useEffect(() => {
|
||||||
setBuild([...build, part]);
|
async function fetchProducts() {
|
||||||
setPart("");
|
try {
|
||||||
|
const response = await fetch("/api/products"); // Replace with your actual API endpoint
|
||||||
|
const data = await response.json();
|
||||||
|
setProducts(data);
|
||||||
|
setLoading(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching products:", error);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
fetchProducts();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Add a product to the build
|
||||||
|
const addToBuild = (product) => {
|
||||||
|
setBuild((prevBuild) => [...prevBuild, product]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removePartFromBuild = (index) => {
|
// Remove a product from the build
|
||||||
setBuild(build.filter((_, i) => i !== index));
|
const removeFromBuild = (productId) => {
|
||||||
|
setBuild((prevBuild) => prevBuild.filter((item) => item.id !== productId));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-gray-100 min-h-screen p-6">
|
<div className="bg-gray-100 min-h-screen p-6">
|
||||||
<div className="max-w-3xl mx-auto">
|
<div className="max-w-5xl mx-auto">
|
||||||
<h1 className="text-3xl font-bold text-center mb-6">Build Your Firearm</h1>
|
<h1 className="text-3xl font-bold text-center mb-6">Build Your Firearm</h1>
|
||||||
|
|
||||||
|
{/* Available Products */}
|
||||||
|
<div className="bg-white shadow-md rounded p-6 mb-6">
|
||||||
|
<h2 className="text-xl font-bold mb-4">Available Products</h2>
|
||||||
|
{loading ? (
|
||||||
|
<p className="text-gray-700">Loading products...</p>
|
||||||
|
) : (
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
|
{products.map((product) => (
|
||||||
|
<div key={product.id} className="bg-gray-100 shadow rounded p-4">
|
||||||
|
<h3 className="text-lg font-bold">{product.name}</h3>
|
||||||
|
<p className="text-gray-700">{product.description}</p>
|
||||||
|
<p className="text-gray-900 font-bold">${product.price}</p>
|
||||||
|
<button
|
||||||
|
className="bg-blue-500 text-white px-4 py-2 rounded mt-4 hover:bg-blue-700"
|
||||||
|
onClick={() => addToBuild(product)}
|
||||||
|
>
|
||||||
|
Add to Build
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Current Build */}
|
||||||
<div className="bg-white shadow-md rounded p-6">
|
<div className="bg-white shadow-md rounded p-6">
|
||||||
<div className="flex items-center space-x-4">
|
<h2 className="text-xl font-bold mb-4">Current Build</h2>
|
||||||
<input
|
{build.length === 0 ? (
|
||||||
type="text"
|
<p className="text-gray-700">No parts added yet. Start building your firearm!</p>
|
||||||
placeholder="Enter part name (e.g., Barrel, Scope)"
|
) : (
|
||||||
className="border border-gray-300 p-2 rounded w-full"
|
<ul className="list-disc list-inside">
|
||||||
value={part}
|
{build.map((item) => (
|
||||||
onChange={(e) => setPart(e.target.value)}
|
<li key={item.id} className="flex justify-between items-center">
|
||||||
/>
|
<span>{item.name}</span>
|
||||||
<button
|
<button
|
||||||
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700"
|
className="text-red-500 hover:underline"
|
||||||
onClick={addPartToBuild}
|
onClick={() => removeFromBuild(item.id)}
|
||||||
>
|
>
|
||||||
Add Part
|
Remove
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</li>
|
||||||
<h2 className="text-xl font-bold mt-6">Current Build</h2>
|
))}
|
||||||
<ul className="list-disc list-inside mt-4">
|
</ul>
|
||||||
{build.map((p, index) => (
|
)}
|
||||||
<li key={index} className="flex justify-between items-center">
|
|
||||||
<span>{p}</span>
|
|
||||||
<button
|
|
||||||
className="text-red-500 hover:underline"
|
|
||||||
onClick={() => removePartFromBuild(index)}
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user