@@ -110,4 +110,105 @@ export const OwnedStructuresFullList = () => {
110
110
// <SectorStructureOwned sectorid="18" />
111
111
< SectorStructureOwnedAllSectorsOneUser />
112
112
) ;
113
- } ;
113
+ } ;
114
+
115
+ interface StructureItem {
116
+ id : bigint ;
117
+ name : string ;
118
+ description : string ;
119
+ // Add more properties as needed
120
+ }
121
+
122
+ interface SectorItem {
123
+ id : bigint ;
124
+ // Add more properties as needed
125
+ }
126
+
127
+ interface PlanetData {
128
+ id : bigint ;
129
+ // Add more properties as needed
130
+ }
131
+
132
+ interface PlanetStructuresAndItems {
133
+ planetStructures : StructureItem [ ] ;
134
+ planetItems : StructureItem [ ] ;
135
+ sectorStructures : StructureItem [ ] ;
136
+ sectorItems : StructureItem [ ] ;
137
+ }
138
+
139
+ export const StructuresAndItemsComponent : React . FC = ( ) => {
140
+ const supabase = useSupabaseClient ( ) ;
141
+ let [ planetId , setPlanetId ] = useState < string | null > ( null ) ;
142
+ let [ sectorId , setSectorId ] = useState < string | null > ( null ) ;
143
+ const [ structuresAndItems , setStructuresAndItems ] = useState < PlanetStructuresAndItems | null > ( null ) ;
144
+
145
+ const fetchStructuresAndItems = async ( ) => {
146
+ try {
147
+ if ( ! planetId ) {
148
+ throw new Error ( "Please provide a planetId" ) ;
149
+ }
150
+
151
+ const fetchedStructuresAndItems : PlanetStructuresAndItems = {
152
+ planetStructures : [ ] ,
153
+ planetItems : [ ] ,
154
+ sectorStructures : [ ] ,
155
+ sectorItems : [ ] ,
156
+ } ;
157
+
158
+ if ( sectorId ) {
159
+ const { data : sectorData , error : sectorError } = await supabase
160
+ . from ( "basePlanetSectors" )
161
+ . select ( "anomaly" )
162
+ . eq ( "id" , sectorId )
163
+ . single ( ) ;
164
+
165
+ if ( sectorError || ! sectorData ) {
166
+ throw new Error ( "Error fetching sector data" ) ;
167
+ }
168
+
169
+ planetId = sectorData . anomaly . toString ( ) ;
170
+ }
171
+
172
+ const { data : planetData , error : planetError } = await supabase
173
+ . from ( "basePlanets" )
174
+ . select ( "*" )
175
+ . eq ( "id" , Number ( planetId ) )
176
+ . single ( ) ;
177
+
178
+ if ( planetError ) {
179
+ throw new Error ( "Error fetching planet data" ) ;
180
+ }
181
+
182
+ setStructuresAndItems ( fetchedStructuresAndItems ) ;
183
+ } catch ( error ) {
184
+ console . error ( "Error fetching structures and items:" , error ) ;
185
+ }
186
+ } ;
187
+
188
+ const handleSubmit = ( event : React . FormEvent < HTMLFormElement > ) => {
189
+ event . preventDefault ( ) ;
190
+ fetchStructuresAndItems ( ) ;
191
+ } ;
192
+
193
+ // Render the form to input planetId and sectorId
194
+ return (
195
+ < form onSubmit = { handleSubmit } >
196
+ < label >
197
+ Planet ID:
198
+ < input type = "number" value = { planetId ?? '' } onChange = { ( e ) => setPlanetId ( e . target . value ) } />
199
+ </ label >
200
+ < label >
201
+ Sector ID:
202
+ < input type = "number" value = { sectorId ?? '' } onChange = { ( e ) => setSectorId ( e . target . value ) } />
203
+ </ label >
204
+ < button type = "submit" > Fetch Structures and Items</ button >
205
+
206
+ { /* Render the structures and items data */ }
207
+ { structuresAndItems && (
208
+ < div >
209
+ { /* Render structures and items here */ }
210
+ </ div >
211
+ ) }
212
+ </ form >
213
+ ) ;
214
+ } ;
0 commit comments