Skip to content

Commit d1e79b2

Browse files
committed
🎩⭐️ ↝ oh that took forever. Can (finally) communicate via post to papyrus.
1 parent 7c56a32 commit d1e79b2

File tree

1 file changed

+86
-2
lines changed

1 file changed

+86
-2
lines changed

components/Content/Planets/Activities/StructureCreate.tsx

+86-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, useState } from "react";
22
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
3+
import axios from "axios";
34

45
interface Structure {
56
id: number;
@@ -70,9 +71,40 @@ const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSele
7071
fetchStructures();
7172
}, [supabase]);
7273

73-
const handleStructureClick = (structure: Structure) => {
74+
const handleStructureClick = async (structure: Structure) => {
75+
try {
76+
if (!session) {
77+
console.error("User session not available!");
78+
return;
79+
};
80+
81+
const payload = {
82+
user_id: session?.user?.id,
83+
structure_id: structure.id,
84+
};
85+
86+
console.log(payload);
87+
88+
const response = await fetch("http://127.0.0.1:5000/craft_structure", {
89+
method: "POST",
90+
headers: {
91+
"Content-Type": "application/json",
92+
},
93+
body: JSON.stringify(payload),
94+
});
95+
96+
if (!response.ok) {
97+
throw new Error(`HTTP Error! Status: ${response.status}`)
98+
};
99+
100+
const data = await response.json();
101+
console.log(data);
102+
} catch (error) {
103+
console.error(error.message);
104+
};
105+
74106
onStructureSelected(structure);
75-
createInventoryUserEntry(structure);
107+
// createInventoryUserEntry(structure);
76108
setIsCalloutOpen(false);
77109
};
78110

@@ -174,6 +206,7 @@ export const PlacedStructures: React.FC<PlacedStructuresProps> = ({ sectorId })
174206
return (
175207
<div>
176208
<h2>Structures Placed on Sector {sectorId}</h2>
209+
<CraftButton />
177210
<div>
178211
{placedStructures.map((structure) => (
179212
<div key={structure.id}>
@@ -185,4 +218,55 @@ export const PlacedStructures: React.FC<PlacedStructuresProps> = ({ sectorId })
185218
</div>
186219
</div>
187220
);
221+
};
222+
223+
const CraftButton = () => {
224+
const handleClick = async () => {
225+
try {
226+
const payload = JSON.stringify({
227+
user_id: "cebdc7a2-d8af-45b3-b37f-80f328ff54d6",
228+
structure_id: 14
229+
});
230+
231+
const response = await fetch('http://127.0.0.1:5000/craft_structure', {
232+
method: 'POST',
233+
headers: {
234+
'Content-Type': 'application/json'
235+
},
236+
body: payload
237+
});
238+
239+
const data = await response.json();
240+
console.log('Response from Flask:', data);
241+
} catch (error) {
242+
console.error('Error:', error.message);
243+
}
244+
};
245+
246+
return (
247+
<button onClick={handleClick}>
248+
Craft Structure
249+
</button>
250+
);
251+
};
252+
253+
const ItemListFetcher = () => {
254+
useEffect(() => {
255+
const fetchItems = async () => {
256+
try {
257+
const response = await axios.get('http://127.0.0.1:5000/items');
258+
console.log('Items:', response.data);
259+
} catch (error) {
260+
console.error('Error fetching items:', error.message);
261+
}
262+
};
263+
264+
fetchItems();
265+
}, []);
266+
267+
return (
268+
<div>
269+
Fetching items...
270+
</div>
271+
);
188272
};

0 commit comments

Comments
 (0)