Skip to content

Commit 55b4775

Browse files
committed
🤑👟 ↝ [SGV2-18 SGV2-16]: Block that will show sector/planet inventory collectively (prev commit SGV2-18)
1 parent b8ff1ab commit 55b4775

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed

‎components/_Core/Section/BentoBox.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { cn } from "../../../lib/uitls";
33
import { RocketIcon } from "lucide-react";
44
import { BentoGrid, BentoGridTest } from "../ui/bento-grid";
5-
import { InventoryOneList, InventoryTwoList, OwnedStructuresFullList } from "../../_Skeleton/InventoryBlocks";
5+
import { InventoryOneList, InventoryTwoList, OwnedStructuresFullList, StructuresAndItemsComponent } from "../../_Skeleton/InventoryBlocks";
66
import { ClassificationForPlanetFormBlock } from "../../_Skeleton/ClassificationBlocks";
77
import { ContentPlaceholderBlockTest, PlanetStatBlock, SectorsInsidePlanetBlock, StructuresOnPlanetBlock } from "../../_Skeleton/PlanetDataBlocks";
88
import { AddResourceToInventoryBlock, SectorRoverImageClassificationBlock } from "../../_Skeleton/SectorDataBlocks";
@@ -207,6 +207,17 @@ const items = [
207207
header: <CreateStructureBlock />,
208208
className: "md:col-span-1 row-span-1"
209209
},
210+
{
211+
title: "Get a list of structures/items across a specific planet and all sectors relative",
212+
description: (
213+
<span className="text-sm">
214+
It should result in a single react component that you input a planet id and a structure id, click a button, and it then responds with a text element with that context
215+
</span>
216+
),
217+
icon: RocketIcon,
218+
header: <StructuresAndItemsComponent />,
219+
className: "md:col-span-1 row-span-1"
220+
},
210221
{
211222
title: "Data/stat display for an anomaly ",
212223
description: (

‎components/_Skeleton/InventoryBlocks.tsx

+102-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,105 @@ export const OwnedStructuresFullList = () => {
110110
// <SectorStructureOwned sectorid="18" />
111111
<SectorStructureOwnedAllSectorsOneUser />
112112
);
113-
};
113+
};
114+
115+
interface StructureItem {
116+
id: bigint;
117+
name: string;
118+
description: string;
119+
// Add more properties as needed
120+
}
121+
122+
interface SectorItem {
123+
id: bigint;
124+
// Add more properties as needed
125+
}
126+
127+
interface PlanetData {
128+
id: bigint;
129+
// Add more properties as needed
130+
}
131+
132+
interface PlanetStructuresAndItems {
133+
planetStructures: StructureItem[];
134+
planetItems: StructureItem[];
135+
sectorStructures: StructureItem[];
136+
sectorItems: StructureItem[];
137+
}
138+
139+
export const StructuresAndItemsComponent: React.FC = () => {
140+
const supabase = useSupabaseClient();
141+
let [planetId, setPlanetId] = useState<string | null>(null);
142+
let [sectorId, setSectorId] = useState<string | null>(null);
143+
const [structuresAndItems, setStructuresAndItems] = useState<PlanetStructuresAndItems | null>(null);
144+
145+
const fetchStructuresAndItems = async () => {
146+
try {
147+
if (!planetId) {
148+
throw new Error("Please provide a planetId");
149+
}
150+
151+
const fetchedStructuresAndItems: PlanetStructuresAndItems = {
152+
planetStructures: [],
153+
planetItems: [],
154+
sectorStructures: [],
155+
sectorItems: [],
156+
};
157+
158+
if (sectorId) {
159+
const { data: sectorData, error: sectorError } = await supabase
160+
.from("basePlanetSectors")
161+
.select("anomaly")
162+
.eq("id", sectorId)
163+
.single();
164+
165+
if (sectorError || !sectorData) {
166+
throw new Error("Error fetching sector data");
167+
}
168+
169+
planetId = sectorData.anomaly.toString();
170+
}
171+
172+
const { data: planetData, error: planetError } = await supabase
173+
.from("basePlanets")
174+
.select("*")
175+
.eq("id", Number(planetId))
176+
.single();
177+
178+
if (planetError) {
179+
throw new Error("Error fetching planet data");
180+
}
181+
182+
setStructuresAndItems(fetchedStructuresAndItems);
183+
} catch (error) {
184+
console.error("Error fetching structures and items:", error);
185+
}
186+
};
187+
188+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
189+
event.preventDefault();
190+
fetchStructuresAndItems();
191+
};
192+
193+
// Render the form to input planetId and sectorId
194+
return (
195+
<form onSubmit={handleSubmit}>
196+
<label>
197+
Planet ID:
198+
<input type="number" value={planetId ?? ''} onChange={(e) => setPlanetId(e.target.value)} />
199+
</label>
200+
<label>
201+
Sector ID:
202+
<input type="number" value={sectorId ?? ''} onChange={(e) => setSectorId(e.target.value)} />
203+
</label>
204+
<button type="submit">Fetch Structures and Items</button>
205+
206+
{/* Render the structures and items data */}
207+
{structuresAndItems && (
208+
<div>
209+
{/* Render structures and items here */}
210+
</div>
211+
)}
212+
</form>
213+
);
214+
};

0 commit comments

Comments
 (0)