Skip to content

Commit 3e7e72a

Browse files
committed
πŸ“˜πŸͺ ↝ [SSG-68]: Fix mission table entry
1 parent aeedda6 commit 3e7e72a

File tree

1 file changed

+67
-69
lines changed

1 file changed

+67
-69
lines changed

β€Žcomponents/Layout/Guide.tsx

+67-69
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
77
import { useActivePlanet } from "@/context/ActivePlanet";
88

99
interface Mission {
10-
id: number | number[];
10+
id: number | number[];
1111
name: string;
1212
description: string;
1313
icon: React.ElementType;
@@ -23,14 +23,6 @@ interface DialogueStep {
2323
};
2424

2525
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-
// },
3426
{
3527
id: 3000001,
3628
name: "Complete an astronomy mission using your telescope",
@@ -72,20 +64,6 @@ const meteorologyMissions: Mission[] = [
7264
];
7365

7466
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-
// },
8967
{
9068
id: 3000001,
9169
name: "Discover a new planet",
@@ -120,14 +98,6 @@ const globalMissions: Mission[] = [
12098
},
12199
];
122100

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-
131101
const StructureMissionGuide = () => {
132102
const supabase = useSupabaseClient();
133103
const session = useSession();
@@ -148,70 +118,101 @@ const StructureMissionGuide = () => {
148118
useEffect(() => {
149119
async function fetchInventoryAndCompletedMissions() {
150120
if (!session?.user?.id || !activePlanet?.id) return;
151-
121+
152122
try {
153123
const { data: inventoryData } = await supabase
154124
.from('inventory')
155125
.select('item')
156126
.eq('owner', session.user.id)
157127
.eq('anomaly', activePlanet.id)
158128
.in('item', [3103, 3104, 3105]);
159-
129+
160130
const ownedItems = inventoryData ? inventoryData.map((inv: { item: number }) => inv.item) : [];
161131
setOwnedItems(ownedItems);
162-
132+
133+
// Fetch completed missions
163134
const { data: missionData } = await supabase
164135
.from('missions')
165136
.select('mission')
166137
.eq('user', session.user.id);
167-
138+
168139
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+
169160
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);
180162
} catch (error) {
181163
console.error("Error fetching inventory or missions:", error);
164+
setLoading(false);
182165
}
183-
setLoading(false);
184166
}
185-
167+
186168
fetchInventoryAndCompletedMissions();
187169
}, [session, activePlanet, supabase]);
188-
170+
189171
useEffect(() => {
190-
// Get the current category's missions
191172
const currentMissions = categories[currentCategory].missions;
192173

193-
// Filter global missions based on category and owned items
194174
const filteredGlobalMissions = globalMissions.filter((mission) => {
195-
// Example: Only show astronomy-specific missions if requiredItem matches owned items
196175
if (mission.requiredItem && !ownedItems.includes(mission.requiredItem)) {
197-
return false; // Do not display if required item is not owned
176+
return false;
198177
}
199-
return true; // Display if no restrictions
178+
return true;
200179
});
201180

202-
// Combine current category missions with filtered global missions
203181
const missionsToDisplay = [
204182
...currentMissions,
205183
...filteredGlobalMissions,
206184
];
207185

208-
// Remove duplicates based on mission id
209186
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(),
211188
];
212189

213190
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]);
215216

216217
const renderMission = (mission: Mission) => {
217218
const missionId = Array.isArray(mission.id) ? mission.id[0] : mission.id;
@@ -250,23 +251,20 @@ const StructureMissionGuide = () => {
250251
<Button onClick={previousCategory} className="p-2 text-gray-300">
251252
<ChevronLeft className="w-6 h-6" />
252253
</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>
256255
<Button onClick={nextCategory} className="p-2 text-gray-300">
257256
<ChevronRight className="w-6 h-6" />
258257
</Button>
259258
</div>
260-
259+
<AnimatePresence>
261260
<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>
270268
</CardContent>
271269
</div>
272270
</div>

0 commit comments

Comments
Β (0)