@@ -7,7 +7,7 @@ import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
7
7
import { useActivePlanet } from "@/context/ActivePlanet" ;
8
8
9
9
interface Mission {
10
- id : number | number [ ] ;
10
+ id : number | number [ ] ;
11
11
name : string ;
12
12
description : string ;
13
13
icon : React . ElementType ;
@@ -23,14 +23,6 @@ interface DialogueStep {
23
23
} ;
24
24
25
25
const astronomyMissions : Mission [ ] = [
26
- // {
27
- // id: [3000001, 20000004,], // 3000002],
28
- // name: "Complete a mission using your created structure",
29
- // description: "Click on the structure you created to make some classifications",
30
- // icon: Telescope,
31
- // color: 'text-cyan-300',
32
- // requiredItem: 3103,
33
- // },
34
26
{
35
27
id : 3000001 ,
36
28
name : "Complete an astronomy mission using your telescope" ,
@@ -72,20 +64,6 @@ const meteorologyMissions: Mission[] = [
72
64
] ;
73
65
74
66
const globalMissions : Mission [ ] = [
75
- // {
76
- // id: 2000000015,
77
- // name: "Research a new module",
78
- // description: 'Click on your structure and then the "Research" tab to unlock new projects and data sources to contribute to!',
79
- // icon: TestTube2,
80
- // color: 'text-purple-300',
81
- // },
82
- // {
83
- // id: 200000013,
84
- // name: "Collect some fuel",
85
- // description: "Click on the mining tab to visit some mineral deposits your probes have found and mine them for fuel",
86
- // icon: Pickaxe,
87
- // color: 'text-red-300',
88
- // },
89
67
{
90
68
id : 3000001 ,
91
69
name : "Discover a new planet" ,
@@ -120,14 +98,6 @@ const globalMissions: Mission[] = [
120
98
} ,
121
99
] ;
122
100
123
- // Research station - walk the user through this. Then upload data, verify/vet (consensus), then we introduce travel. Add a "close"/swipe-down option so that the tutorial section can be hidden/minimised. Then we go through the guide for the different views....and determine the differentials from Pathway.tsx and this new list
124
- // As well as researching for other projects/mission modules that aren't in `mission-selector`
125
- // We'll also need to update this for different planets & chapters
126
-
127
- const dialogueSteps : DialogueStep [ ] = [
128
-
129
- ] ;
130
-
131
101
const StructureMissionGuide = ( ) => {
132
102
const supabase = useSupabaseClient ( ) ;
133
103
const session = useSession ( ) ;
@@ -148,70 +118,101 @@ const StructureMissionGuide = () => {
148
118
useEffect ( ( ) => {
149
119
async function fetchInventoryAndCompletedMissions ( ) {
150
120
if ( ! session ?. user ?. id || ! activePlanet ?. id ) return ;
151
-
121
+
152
122
try {
153
123
const { data : inventoryData } = await supabase
154
124
. from ( 'inventory' )
155
125
. select ( 'item' )
156
126
. eq ( 'owner' , session . user . id )
157
127
. eq ( 'anomaly' , activePlanet . id )
158
128
. in ( 'item' , [ 3103 , 3104 , 3105 ] ) ;
159
-
129
+
160
130
const ownedItems = inventoryData ? inventoryData . map ( ( inv : { item : number } ) => inv . item ) : [ ] ;
161
131
setOwnedItems ( ownedItems ) ;
162
-
132
+
133
+ // Fetch completed missions
163
134
const { data : missionData } = await supabase
164
135
. from ( 'missions' )
165
136
. select ( 'mission' )
166
137
. eq ( 'user' , session . user . id ) ;
167
-
138
+
168
139
const completedMissionIds = missionData ? missionData . map ( ( mission : { mission : number } ) => mission . mission ) : [ ] ;
140
+
141
+ // Check missions with tableEntry and tableColumn
142
+ const additionalChecks = await Promise . all ( globalMissions . map ( async ( mission ) => {
143
+ if ( mission . tableEntry && mission . tableColumn ) {
144
+ const { data : tableData } = await supabase
145
+ . from ( mission . tableEntry )
146
+ . select ( '*' )
147
+ . eq ( mission . tableColumn , session . user . id ) ;
148
+
149
+ if ( tableData && tableData . length > 0 ) {
150
+ // Check if mission.id is an array, and if so, push the first element
151
+ if ( Array . isArray ( mission . id ) ) {
152
+ completedMissionIds . push ( mission . id [ 0 ] ) ; // Pushing the first element of the array
153
+ } else {
154
+ completedMissionIds . push ( mission . id ) ; // Otherwise, push the number directly
155
+ }
156
+ }
157
+ }
158
+ } ) ) ;
159
+
169
160
setCompletedMissions ( completedMissionIds ) ;
170
-
171
- if ( ownedItems . includes ( 3103 ) ) {
172
- setCurrentCategory ( 0 ) ; // Astronomy
173
- } else if ( ownedItems . includes ( 3104 ) ) {
174
- setCurrentCategory ( 1 ) ; // Biology
175
- } else if ( ownedItems . includes ( 3105 ) ) {
176
- setCurrentCategory ( 2 ) ; // Meteorology
177
- } else {
178
- setCurrentCategory ( 0 ) ; // Default to Astronomy
179
- }
161
+ setLoading ( false ) ;
180
162
} catch ( error ) {
181
163
console . error ( "Error fetching inventory or missions:" , error ) ;
164
+ setLoading ( false ) ;
182
165
}
183
- setLoading ( false ) ;
184
166
}
185
-
167
+
186
168
fetchInventoryAndCompletedMissions ( ) ;
187
169
} , [ session , activePlanet , supabase ] ) ;
188
-
170
+
189
171
useEffect ( ( ) => {
190
- // Get the current category's missions
191
172
const currentMissions = categories [ currentCategory ] . missions ;
192
173
193
- // Filter global missions based on category and owned items
194
174
const filteredGlobalMissions = globalMissions . filter ( ( mission ) => {
195
- // Example: Only show astronomy-specific missions if requiredItem matches owned items
196
175
if ( mission . requiredItem && ! ownedItems . includes ( mission . requiredItem ) ) {
197
- return false ; // Do not display if required item is not owned
176
+ return false ;
198
177
}
199
- return true ; // Display if no restrictions
178
+ return true ;
200
179
} ) ;
201
180
202
- // Combine current category missions with filtered global missions
203
181
const missionsToDisplay = [
204
182
...currentMissions ,
205
183
...filteredGlobalMissions ,
206
184
] ;
207
185
208
- // Remove duplicates based on mission id
209
186
const uniqueMissions = [
210
- ...new Map ( missionsToDisplay . map ( mission => [ mission . id , mission ] ) ) . values ( ) ,
187
+ ...new Map ( missionsToDisplay . map ( mission => [ Array . isArray ( mission . id ) ? mission . id [ 0 ] : mission . id , mission ] ) ) . values ( ) ,
211
188
] ;
212
189
213
190
setScrollableMissions ( uniqueMissions ) ;
214
- } , [ currentCategory , ownedItems ] ) ;
191
+ } , [ currentCategory , ownedItems ] ) ;
192
+
193
+
194
+
195
+ useEffect ( ( ) => {
196
+ const currentMissions = categories [ currentCategory ] . missions ;
197
+
198
+ const filteredGlobalMissions = globalMissions . filter ( ( mission ) => {
199
+ if ( mission . requiredItem && ! ownedItems . includes ( mission . requiredItem ) ) {
200
+ return false ;
201
+ }
202
+ return true ;
203
+ } ) ;
204
+
205
+ const missionsToDisplay = [
206
+ ...currentMissions ,
207
+ ...filteredGlobalMissions ,
208
+ ] ;
209
+
210
+ const uniqueMissions = [
211
+ ...new Map ( missionsToDisplay . map ( mission => [ mission . id , mission ] ) ) . values ( ) ,
212
+ ] ;
213
+
214
+ setScrollableMissions ( uniqueMissions ) ;
215
+ } , [ currentCategory , ownedItems ] ) ;
215
216
216
217
const renderMission = ( mission : Mission ) => {
217
218
const missionId = Array . isArray ( mission . id ) ? mission . id [ 0 ] : mission . id ;
@@ -250,23 +251,20 @@ const StructureMissionGuide = () => {
250
251
< Button onClick = { previousCategory } className = "p-2 text-gray-300" >
251
252
< ChevronLeft className = "w-6 h-6" />
252
253
</ Button >
253
- < h2 className = "text-xl font-semibold text-gray-200" >
254
- { categories [ currentCategory ] . name } Missions
255
- </ h2 >
254
+ < h2 className = "text-xl font-semibold text-gray-200" > { categories [ currentCategory ] . name } </ h2 >
256
255
< Button onClick = { nextCategory } className = "p-2 text-gray-300" >
257
256
< ChevronRight className = "w-6 h-6" />
258
257
</ Button >
259
258
</ div >
260
-
259
+ < AnimatePresence >
261
260
< div className = "overflow-y-auto max-h-40 space-y-2" >
262
- { ! loading && scrollableMissions . length > 0 ? (
263
- < div className = "space-y-2" >
264
- { scrollableMissions . map ( ( mission ) => renderMission ( mission ) ) }
265
- </ div >
266
- ) : (
267
- < p className = "text-gray-400" > No missions available.</ p >
268
- ) }
269
- </ div >
261
+ { loading ? (
262
+ < div > Loading...</ div >
263
+ ) : (
264
+ scrollableMissions . map ( renderMission )
265
+ ) }
266
+ </ div >
267
+ </ AnimatePresence >
270
268
</ CardContent >
271
269
</ div >
272
270
</ div >
0 commit comments