diff --git a/components/Content/Populate/StructureCreate.tsx b/components/Content/Populate/StructureCreate.tsx index 61454d2b..9ab4fc9b 100644 --- a/components/Content/Populate/StructureCreate.tsx +++ b/components/Content/Populate/StructureCreate.tsx @@ -31,7 +31,7 @@ interface StructureSelectionProps { planetSectorId: number; }; -const StructureSelection: React.FC = ({ onStructureSelected, planetSectorId }) => { +export const StructureSelection: React.FC = ({ onStructureSelected, planetSectorId }) => { const supabase = useSupabaseClient(); const session = useSession(); diff --git a/components/_Core/Section/BentoBox.tsx b/components/_Core/Section/BentoBox.tsx index f19112f1..376a98a7 100644 --- a/components/_Core/Section/BentoBox.tsx +++ b/components/_Core/Section/BentoBox.tsx @@ -7,6 +7,8 @@ import { ClassificationForPlanetFormBlock } from "../../_Skeleton/Classification import { ContentPlaceholderBlockTest, PlanetStatBlock, SectorsInsidePlanetBlock, StructuresOnPlanetBlock } from "../../_Skeleton/PlanetDataBlocks"; import { AddResourceToInventoryBlock, SectorRoverImageClassificationBlock } from "../../_Skeleton/SectorDataBlocks"; import { LightcurveBaseGraph } from "../../_Skeleton/ClassificationDataBlocks"; +import { ItemListFromFlaskBlock } from "../../_Skeleton/ItemBlocks"; +import { CreateStructureBlock } from "../../_Skeleton/StructureBlocks"; export default function BlockGrid() { return ( @@ -183,6 +185,28 @@ const items = [ header: , className: "md:col-span-1 row-span-1" }, + { + title: "Get a list of all items in the database/crafting recipes via the API (not currently functional)", + description: ( + + Currently not working as it is assuming flask is running locally + + ), + icon: RocketIcon, + header: , + className: "md:col-span-1 row-span-1" + }, + { + title: "Create a structure via flask on a specific sector, which checks the crafting & other requirements/performs specific [population] actions (not currently functional)", + description: ( + + Currently not working as the flask link has become deprecated + + ), + icon: RocketIcon, + header: , + className: "md:col-span-1 row-span-1" + }, { title: "Data/stat display for an anomaly ", description: ( diff --git a/components/_Skeleton/ItemBlocks.tsx b/components/_Skeleton/ItemBlocks.tsx new file mode 100644 index 00000000..49e9f26c --- /dev/null +++ b/components/_Skeleton/ItemBlocks.tsx @@ -0,0 +1,23 @@ +import { useEffect } from "react"; +import axios from "axios"; + +export const ItemListFromFlaskBlock = () => { + useEffect(() => { + const fetchItems = async () => { + try { + const response = await axios.get('http://127.0.0.1:5000/items'); + console.log('Items:', response.data); + } catch (error) { + console.error('Error fetching items:', error.message); + } + }; + + fetchItems(); + }, []); + + return ( +
+ Fetching items... +
+ ); +}; \ No newline at end of file diff --git a/components/_Skeleton/StructureBlocks.tsx b/components/_Skeleton/StructureBlocks.tsx index e69de29b..f3557449 100644 --- a/components/_Skeleton/StructureBlocks.tsx +++ b/components/_Skeleton/StructureBlocks.tsx @@ -0,0 +1,131 @@ +import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; +import { useEffect, useState } from "react"; +import StructureComponent from "../Content/Populate/StructureCreate"; + +interface Structure { + id: number; + name: string; + description: string; + icon_url: string; + }; + + interface PlacedStructure extends Structure { + present: boolean; + }; + + interface PlanetData { + anomaly: any[]; // Update the type of 'anomaly' as needed + lightkurve: any; + }; + + interface CraftStructurePayload { + user_id: string; + sector_id: number; + structure_id: number; + }; + + interface StructureSelectionProps { + onStructureSelected: (structure: Structure) => void; + planetSectorId: number; + }; + +const CreateStructureBlockBackbone = () => { + const supabase = useSupabaseClient(); + const session = useSession(); + + const [structures, setStructures] = useState([]); + const [isCalloutOpen, setIsCalloutOpen] = useState(false); + const planetSectorId = 18; + + const fetchStructures = async () => { + try { + const { data, error } = await supabase + .from('inventoryITEMS') + .select('id, name, description, icon_url') + .eq('ItemCategory', 'Structure'); + + if (data) { + setStructures(data); + } + + if (error) { + console.error(error.message); + } + } catch (error) { + console.error(error.message); + } + }; + + useEffect(() => { + fetchStructures(); + }, [supabase]); + + const handleStructureClick = async (structure: Structure) => { + try { + const payload = JSON.stringify({ + user_id: session?.user?.id, + sector_id: planetSectorId, + structure_id: structure.id, + }); + + const response = await fetch('https://papyrus-production.up.railway.app/craft_structure', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: payload + }); + + const data = await response.json(); + console.log('Response from Flask:', data); + + // if (data.status === 'proceed') { // If the status is 'proceed', call createInventoryUserEntry + // createInventoryUserEntry(structure); + // } + } catch (error) { + console.error('Error:', error.message); + } + + // onStructureSelected(structure); + // createInventoryUserEntry(structure) + setIsCalloutOpen(false); + }; + + return ( +
+ + + {isCalloutOpen && ( +
+
+ {structures.map((structure) => ( +
handleStructureClick(structure)} + > +
+ {structure.name} + {structure.name} +
+ {structure.description} +
+ ))} +
+
+ )} +
+ ); +}; + +export const CreateStructureBlock = () => { + return ( + + ); +}; \ No newline at end of file