Skip to content

Commit 1f43b08

Browse files
committed
🧶☘️ ↝ Can now create structures on each sector!
1 parent 1dd8bb0 commit 1f43b08

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

components/Content/Planets/Activities/StructureCreate.tsx

+38-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import { useSupabaseClient } from "@supabase/auth-helpers-react";
2+
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
33

44
interface Structure {
55
id: number;
@@ -10,13 +10,14 @@ interface Structure {
1010

1111
interface StructureSelectionProps {
1212
onStructureSelected: (structure: Structure) => void;
13+
planetSectorId: number;
1314
};
1415

15-
const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSelected }) => {
16+
const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSelected, planetSectorId }) => {
1617
const supabase = useSupabaseClient();
18+
const session = useSession();
1719

1820
const [structures, setStructures] = useState<Structure[]>([]);
19-
2021
const [isCalloutOpen, setIsCalloutOpen] = useState(false);
2122

2223
const fetchStructures = async () => {
@@ -28,14 +29,41 @@ const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSele
2829

2930
if (data) {
3031
setStructures(data);
31-
};
32+
}
3233

3334
if (error) {
3435
console.error(error.message);
35-
};
36+
}
3637
} catch (error) {
3738
console.error(error.message);
38-
};
39+
}
40+
};
41+
42+
const createInventoryUserEntry = async (structure: Structure) => {
43+
if (session && planetSectorId) {
44+
try {
45+
const { data, error } = await supabase
46+
.from('inventoryUSERS')
47+
.upsert([
48+
{
49+
item: structure.id,
50+
owner: session.user.id,
51+
quantity: 1, // You can adjust the quantity as needed
52+
planetSector: planetSectorId,
53+
},
54+
]);
55+
56+
if (data) {
57+
console.log('Inventory user entry created:', data);
58+
}
59+
60+
if (error) {
61+
console.error(error.message);
62+
}
63+
} catch (error) {
64+
console.error(error.message);
65+
}
66+
}
3967
};
4068

4169
useEffect(() => {
@@ -44,6 +72,7 @@ const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSele
4472

4573
const handleStructureClick = (structure: Structure) => {
4674
onStructureSelected(structure);
75+
createInventoryUserEntry(structure);
4776
setIsCalloutOpen(false);
4877
};
4978

@@ -67,7 +96,7 @@ const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSele
6796
onClick={() => handleStructureClick(structure)}
6897
>
6998
<div className="flex items-center space-x-2">
70-
<img src={structure.icon_url} alt={structure.name} className="w-9 h-9" />
99+
<img src={structure.icon_url} alt={structure.name} className="w-8 h-8" />
71100
<span className="font-bold">{structure.name}</span>
72101
</div>
73102
<span className="text-gray-500">{structure.description}</span>
@@ -80,14 +109,14 @@ const StructureSelection: React.FC<StructureSelectionProps> = ({ onStructureSele
80109
);
81110
};
82111

83-
export default function StructureComponent () {
112+
export default function StructureComponent({ sectorId }) {
84113
const handleStructureSelected = (structure) => {
85114
console.log('Selected structure: ', structure);
86115
};
87116

88117
return (
89118
<div>
90-
<StructureSelection onStructureSelected={handleStructureSelected} />
119+
<StructureSelection onStructureSelected={handleStructureSelected} planetSectorId={sectorId} />
91120
</div>
92121
);
93122
};

components/Content/Planets/Base/IndividualBasePlanetSector.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Card from "../../../Card";
55
import RoverImageGallery, { RoverImage, RoverImageNoHandle } from "../PlanetData/RandomRoverImage";
66
import axios from "axios";
77
import { RoverContentPostForm } from "../../CreatePostForm";
8+
import StructureComponent from "../Activities/StructureCreate";
89

910
export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
1011
const router = useRouter();
@@ -198,6 +199,7 @@ export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
198199
<div>
199200
<Card noPadding={false}>
200201
<RoverImageNoHandle date='853' rover='opportunity' sectorNo={id} />
202+
<StructureComponent sectorId={sectorid} />
201203
{/* {imageUrl ? (
202204
<>
203205
<img src={imageUrl} alt="Rover image" />

pages/planets/[id].tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function PlanetIdPage () {
9494

9595
return (
9696
<>
97-
{/* <Navbar /> */}
97+
<Navbar />
9898
<div className="h-screen">
9999
<IndividualBasePlanetDesktop id={id as string} />
100100
</div>
@@ -106,8 +106,7 @@ export default function PlanetIdPage () {
106106
<ClassificationFeedForIndividualPlanet
107107
planetId={{ id: id as string }}
108108
backgroundColorSet="bg-blue-200"
109-
/><div className="mx-20">
110-
<div className="px-20 ml-20"><StructureComponent /></div></div>
109+
/>
111110
</div>
112111
<div className="">
113112
<BasePlanetData planetId={{ id: id as string }} />

0 commit comments

Comments
 (0)