diff --git a/components/Content/Planets/Activities/StructureCreate.tsx b/components/Content/Planets/Activities/StructureCreate.tsx index 697dc5ae..ae88c210 100644 --- a/components/Content/Planets/Activities/StructureCreate.tsx +++ b/components/Content/Planets/Activities/StructureCreate.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from "react"; -import { useSupabaseClient } from "@supabase/auth-helpers-react"; +import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; interface Structure { id: number; @@ -10,13 +10,14 @@ interface Structure { interface StructureSelectionProps { onStructureSelected: (structure: Structure) => void; + planetSectorId: number; }; -const StructureSelection: React.FC = ({ onStructureSelected }) => { +const StructureSelection: React.FC = ({ onStructureSelected, planetSectorId }) => { const supabase = useSupabaseClient(); + const session = useSession(); const [structures, setStructures] = useState([]); - const [isCalloutOpen, setIsCalloutOpen] = useState(false); const fetchStructures = async () => { @@ -28,14 +29,41 @@ const StructureSelection: React.FC = ({ onStructureSele if (data) { setStructures(data); - }; + } if (error) { console.error(error.message); - }; + } } catch (error) { console.error(error.message); - }; + } + }; + + const createInventoryUserEntry = async (structure: Structure) => { + if (session && planetSectorId) { + try { + const { data, error } = await supabase + .from('inventoryUSERS') + .upsert([ + { + item: structure.id, + owner: session.user.id, + quantity: 1, // You can adjust the quantity as needed + planetSector: planetSectorId, + }, + ]); + + if (data) { + console.log('Inventory user entry created:', data); + } + + if (error) { + console.error(error.message); + } + } catch (error) { + console.error(error.message); + } + } }; useEffect(() => { @@ -44,6 +72,7 @@ const StructureSelection: React.FC = ({ onStructureSele const handleStructureClick = (structure: Structure) => { onStructureSelected(structure); + createInventoryUserEntry(structure); setIsCalloutOpen(false); }; @@ -67,7 +96,7 @@ const StructureSelection: React.FC = ({ onStructureSele onClick={() => handleStructureClick(structure)} >
- {structure.name} + {structure.name} {structure.name}
{structure.description} @@ -80,14 +109,14 @@ const StructureSelection: React.FC = ({ onStructureSele ); }; -export default function StructureComponent () { +export default function StructureComponent({ sectorId }) { const handleStructureSelected = (structure) => { console.log('Selected structure: ', structure); }; return (
- +
); }; \ No newline at end of file diff --git a/components/Content/Planets/Base/IndividualBasePlanetSector.tsx b/components/Content/Planets/Base/IndividualBasePlanetSector.tsx index ce49745b..7e2a1da6 100644 --- a/components/Content/Planets/Base/IndividualBasePlanetSector.tsx +++ b/components/Content/Planets/Base/IndividualBasePlanetSector.tsx @@ -5,6 +5,7 @@ import Card from "../../../Card"; import RoverImageGallery, { RoverImage, RoverImageNoHandle } from "../PlanetData/RandomRoverImage"; import axios from "axios"; import { RoverContentPostForm } from "../../CreatePostForm"; +import StructureComponent from "../Activities/StructureCreate"; export default function BasePlanetSector({ sectorid }: { sectorid: string }) { const router = useRouter(); @@ -198,6 +199,7 @@ export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
+ {/* {imageUrl ? ( <> Rover image diff --git a/pages/planets/[id].tsx b/pages/planets/[id].tsx index 9121ce8e..04bf0a02 100644 --- a/pages/planets/[id].tsx +++ b/pages/planets/[id].tsx @@ -94,7 +94,7 @@ export default function PlanetIdPage () { return ( <> - {/* */} +
@@ -106,8 +106,7 @@ export default function PlanetIdPage () {
-
+ />