Skip to content

Commit 80784a7

Browse files
committed
🧼👝 ↝ Build menu creation
1 parent ddf402b commit 80784a7

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React, { useEffect, useState } from "react";
2+
import { useSupabaseClient } from "@supabase/auth-helpers-react";
3+
4+
interface Structure {
5+
id: number;
6+
name: string;
7+
description: string;
8+
icon_url: string;
9+
};
10+
11+
interface StructureSelectionProps {
12+
onStructureSelected: (structure: Structure) => void;
13+
};
14+
15+
const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSelected }) => {
16+
const supabase = useSupabaseClient();
17+
18+
const [structures, setStructures] = useState<Structure[]>([]);
19+
20+
const [isCalloutOpen, setIsCalloutOpen] = useState(false);
21+
22+
const fetchStructures = async () => {
23+
try {
24+
const { data, error } = await supabase
25+
.from('inventoryITEMS')
26+
.select('id, name, description, icon_url')
27+
.eq('ItemCategory', 'Structure');
28+
29+
if (data) {
30+
setStructures(data);
31+
};
32+
33+
if (error) {
34+
console.error(error.message);
35+
};
36+
} catch (error) {
37+
console.error(error.message);
38+
};
39+
};
40+
41+
useEffect(() => {
42+
fetchStructures();
43+
}, [supabase]);
44+
45+
const handleStructureClick = (structure: Structure) => {
46+
onStructureSelected(structure);
47+
setIsCalloutOpen(false);
48+
};
49+
50+
return (
51+
<div className="relative inline-block text-left">
52+
<button
53+
type="button"
54+
className="px-4 py-2 text-white bg-blue-500 rounded-md focus:outline-none hover:bg-blue-600"
55+
onClick={() => setIsCalloutOpen(!isCalloutOpen)}
56+
>
57+
Build
58+
</button>
59+
60+
{isCalloutOpen && (
61+
<div className="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5">
62+
<div className="py-1">
63+
{structures.map((structure) => (
64+
<div
65+
key={structure.id}
66+
className="flex items-center justify-between px-4 py-2 hover:bg-gray-100 cursor-pointer"
67+
onClick={() => handleStructureClick(structure)}
68+
>
69+
<div className="flex items-center space-x-2">
70+
<img src={structure.icon_url} alt={structure.name} className="w-6 h-6" />
71+
<span>{structure.name}</span>
72+
</div>
73+
<span className="text-gray-500">{structure.description}</span>
74+
</div>
75+
))}
76+
</div>
77+
</div>
78+
)}
79+
</div>
80+
);
81+
};
82+
83+
export default function StructureComponent () {
84+
const handleStructureSelected = (structure) => {
85+
console.log('Selected structure: ', structure);
86+
};
87+
88+
return (
89+
<div>
90+
<StructureSelection onStructureSelected={handleStructureSelected} />
91+
</div>
92+
);
93+
};

components/Content/Planets/Base/IndividualBasePlanetSector.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Card from "../../../Card";
55
import RoverImageGallery, { RoverImage, RoverImageNoHandle } from "../PlanetData/RandomRoverImage";
66
import axios from "axios";
77
import { RoverContentPostForm } from "../../CreatePostForm";
8+
import StructureComponent from "../Activities/StructureCreate";
89

910
// Rover image data -> place inside BasePlanetSector
1011
// useEffect(() => {
@@ -215,7 +216,8 @@ export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
215216
</div>
216217
</div>
217218
<div className="flex flex-col items-center justify-start gap-4">
218-
<div className="text-center text-slate-300 text-opacity-70 text-[21.73px] font-medium font-['Inter'] uppercase tracking-[3.48px]">
219+
<StructureComponent />
220+
{/* <div className="text-center text-slate-300 text-opacity-70 text-[21.73px] font-medium font-['Inter'] uppercase tracking-[3.48px]">
219221
Mineral deposit
220222
</div>
221223
<div className="text-center text-white text-opacity-90 text-[27.17px] font-medium font-['Inter']">
@@ -227,7 +229,7 @@ export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
227229
alt={`Icon for ${name}`}
228230
className="w-16 h-16 object-contain"
229231
/>
230-
)}
232+
)} */}
231233
</div>
232234
{/* {deposit && typeof deposit === "string" ? (
233235
<div>{deposit}</div>

0 commit comments

Comments
 (0)