Skip to content

Commit e36c468

Browse files
committed
πŸ›£οΈπŸž ↝ [SGV2-10]: Will I find the orchid?
1 parent b112d40 commit e36c468

File tree

4 files changed

+179
-1
lines changed

4 files changed

+179
-1
lines changed

β€Žcomponents/Content/Populate/StructureCreate.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface StructureSelectionProps {
3131
planetSectorId: number;
3232
};
3333

34-
const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSelected, planetSectorId }) => {
34+
export const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSelected, planetSectorId }) => {
3535
const supabase = useSupabaseClient();
3636
const session = useSession();
3737

β€Žcomponents/_Core/Section/BentoBox.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ClassificationForPlanetFormBlock } from "../../_Skeleton/Classification
77
import { ContentPlaceholderBlockTest, PlanetStatBlock, SectorsInsidePlanetBlock, StructuresOnPlanetBlock } from "../../_Skeleton/PlanetDataBlocks";
88
import { AddResourceToInventoryBlock, SectorRoverImageClassificationBlock } from "../../_Skeleton/SectorDataBlocks";
99
import { LightcurveBaseGraph } from "../../_Skeleton/ClassificationDataBlocks";
10+
import { ItemListFromFlaskBlock } from "../../_Skeleton/ItemBlocks";
11+
import { CreateStructureBlock } from "../../_Skeleton/StructureBlocks";
1012

1113
export default function BlockGrid() {
1214
return (
@@ -183,6 +185,28 @@ const items = [
183185
header: <LightcurveBaseGraph />,
184186
className: "md:col-span-1 row-span-1"
185187
},
188+
{
189+
title: "Get a list of all items in the database/crafting recipes via the API (not currently functional)",
190+
description: (
191+
<span className="text-sm">
192+
Currently not working as it is assuming flask is running locally
193+
</span>
194+
),
195+
icon: RocketIcon,
196+
header: <ItemListFromFlaskBlock />,
197+
className: "md:col-span-1 row-span-1"
198+
},
199+
{
200+
title: "Create a structure via flask on a specific sector, which checks the crafting & other requirements/performs specific [population] actions (not currently functional)",
201+
description: (
202+
<span className="text-sm">
203+
Currently not working as the flask link has become deprecated
204+
</span>
205+
),
206+
icon: RocketIcon,
207+
header: <CreateStructureBlock />,
208+
className: "md:col-span-1 row-span-1"
209+
},
186210
{
187211
title: "Data/stat display for an anomaly ",
188212
description: (
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useEffect } from "react";
2+
import axios from "axios";
3+
4+
export const ItemListFromFlaskBlock = () => {
5+
useEffect(() => {
6+
const fetchItems = async () => {
7+
try {
8+
const response = await axios.get('http://127.0.0.1:5000/items');
9+
console.log('Items:', response.data);
10+
} catch (error) {
11+
console.error('Error fetching items:', error.message);
12+
}
13+
};
14+
15+
fetchItems();
16+
}, []);
17+
18+
return (
19+
<div>
20+
Fetching items...
21+
</div>
22+
);
23+
};
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
2+
import { useEffect, useState } from "react";
3+
import StructureComponent from "../Content/Populate/StructureCreate";
4+
5+
interface Structure {
6+
id: number;
7+
name: string;
8+
description: string;
9+
icon_url: string;
10+
};
11+
12+
interface PlacedStructure extends Structure {
13+
present: boolean;
14+
};
15+
16+
interface PlanetData {
17+
anomaly: any[]; // Update the type of 'anomaly' as needed
18+
lightkurve: any;
19+
};
20+
21+
interface CraftStructurePayload {
22+
user_id: string;
23+
sector_id: number;
24+
structure_id: number;
25+
};
26+
27+
interface StructureSelectionProps {
28+
onStructureSelected: (structure: Structure) => void;
29+
planetSectorId: number;
30+
};
31+
32+
const CreateStructureBlockBackbone = () => {
33+
const supabase = useSupabaseClient();
34+
const session = useSession();
35+
36+
const [structures, setStructures] = useState<Structure[]>([]);
37+
const [isCalloutOpen, setIsCalloutOpen] = useState(false);
38+
const planetSectorId = 18;
39+
40+
const fetchStructures = async () => {
41+
try {
42+
const { data, error } = await supabase
43+
.from('inventoryITEMS')
44+
.select('id, name, description, icon_url')
45+
.eq('ItemCategory', 'Structure');
46+
47+
if (data) {
48+
setStructures(data);
49+
}
50+
51+
if (error) {
52+
console.error(error.message);
53+
}
54+
} catch (error) {
55+
console.error(error.message);
56+
}
57+
};
58+
59+
useEffect(() => {
60+
fetchStructures();
61+
}, [supabase]);
62+
63+
const handleStructureClick = async (structure: Structure) => {
64+
try {
65+
const payload = JSON.stringify({
66+
user_id: session?.user?.id,
67+
sector_id: planetSectorId,
68+
structure_id: structure.id,
69+
});
70+
71+
const response = await fetch('https://papyrus-production.up.railway.app/craft_structure', {
72+
method: 'POST',
73+
headers: {
74+
'Content-Type': 'application/json'
75+
},
76+
body: payload
77+
});
78+
79+
const data = await response.json();
80+
console.log('Response from Flask:', data);
81+
82+
// if (data.status === 'proceed') { // If the status is 'proceed', call createInventoryUserEntry
83+
// createInventoryUserEntry(structure);
84+
// }
85+
} catch (error) {
86+
console.error('Error:', error.message);
87+
}
88+
89+
// onStructureSelected(structure);
90+
// createInventoryUserEntry(structure)
91+
setIsCalloutOpen(false);
92+
};
93+
94+
return (
95+
<center><div className="relative inline-block text-center pl-10">
96+
<button
97+
type="button"
98+
className="px-4 py-2 text-white bg-blue-500 rounded-md focus:outline-none hover:bg-blue-600"
99+
onClick={() => setIsCalloutOpen(!isCalloutOpen)}
100+
>
101+
Build
102+
</button>
103+
104+
{isCalloutOpen && (
105+
<div className="origin-top-right absolute right-0 mt-2 w-72 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5">
106+
<div className="py-1">
107+
{structures.map((structure) => (
108+
<div
109+
key={structure.id}
110+
className="flex items-center justify-between px-4 py-2 hover:bg-gray-100 cursor-pointer"
111+
onClick={() => handleStructureClick(structure)}
112+
>
113+
<div className="flex items-center space-x-2 pl-8">
114+
<img src={structure.icon_url} alt={structure.name} className="w-8 h-8" />
115+
<span className="font-bold">{structure.name}</span>
116+
</div>
117+
<span className="text-gray-500">{structure.description}</span>
118+
</div>
119+
))}
120+
</div>
121+
</div>
122+
)}
123+
</div></center>
124+
);
125+
};
126+
127+
export const CreateStructureBlock = () => {
128+
return (
129+
<StructureComponent sectorId={18} />
130+
);
131+
};

0 commit comments

Comments
Β (0)