Skip to content

Commit b5c76a0

Browse files
committed
🕸️🪻 ↝ Can now view all created items on a sector
1 parent 1f43b08 commit b5c76a0

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

components/Content/Planets/Activities/StructureCreate.tsx

+66
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,70 @@ export default function StructureComponent({ sectorId }) {
119119
<StructureSelection onStructureSelected={handleStructureSelected} planetSectorId={sectorId} />
120120
</div>
121121
);
122+
};
123+
124+
interface PlacedStructuresProps {
125+
sectorId: number;
126+
}
127+
128+
interface PlacedStructure {
129+
id: number;
130+
name: string;
131+
description: string;
132+
icon_url: string;
133+
}
134+
135+
export const PlacedStructures: React.FC<PlacedStructuresProps> = ({ sectorId }) => {
136+
const supabase = useSupabaseClient();
137+
const [placedStructures, setPlacedStructures] = useState<PlacedStructure[]>([]);
138+
139+
useEffect(() => {
140+
const fetchPlacedStructures = async () => {
141+
try {
142+
const { data: userItems, error: userItemsError } = await supabase
143+
.from('inventoryUSERS')
144+
.select('item')
145+
.eq('planetSector', sectorId);
146+
147+
if (userItemsError) {
148+
console.error(userItemsError.message);
149+
return;
150+
}
151+
152+
const itemIds = userItems?.map((item) => item.item) || [];
153+
154+
const { data: structureItems, error: structureItemsError } = await supabase
155+
.from('inventoryITEMS')
156+
.select('id, name, description, icon_url')
157+
.in('id', itemIds)
158+
.eq('ItemCategory', 'Structure');
159+
160+
if (structureItemsError) {
161+
console.error(structureItemsError.message);
162+
return;
163+
}
164+
165+
setPlacedStructures(structureItems || []);
166+
} catch (error) {
167+
console.error(error.message);
168+
}
169+
};
170+
171+
fetchPlacedStructures();
172+
}, [supabase, sectorId]);
173+
174+
return (
175+
<div>
176+
<h2>Structures Placed on Sector {sectorId}</h2>
177+
<div>
178+
{placedStructures.map((structure) => (
179+
<div key={structure.id}>
180+
<img src={structure.icon_url} alt={structure.name} />
181+
<p>{structure.name}</p>
182+
<p>{structure.description}</p>
183+
</div>
184+
))}
185+
</div>
186+
</div>
187+
);
122188
};

components/Content/Planets/Base/IndividualBasePlanetSector.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +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";
8+
import StructureComponent, { PlacedStructures } from "../Activities/StructureCreate";
99

1010
export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
1111
const router = useRouter();
@@ -200,6 +200,7 @@ export default function BasePlanetSector({ sectorid }: { sectorid: string }) {
200200
<Card noPadding={false}>
201201
<RoverImageNoHandle date='853' rover='opportunity' sectorNo={id} />
202202
<StructureComponent sectorId={sectorid} />
203+
<PlacedStructures sectorId={Number(sectorid)} />
203204
{/* {imageUrl ? (
204205
<>
205206
<img src={imageUrl} alt="Rover image" />

0 commit comments

Comments
 (0)