@@ -119,4 +119,70 @@ export default function StructureComponent({ sectorId }) {
119
119
< StructureSelection onStructureSelected = { handleStructureSelected } planetSectorId = { sectorId } />
120
120
</ div >
121
121
) ;
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
+ ) ;
122
188
} ;
0 commit comments