Skip to content

Commit 554adc5

Browse files
committed
🥯🛣️ ↝ [SGV2-14 SGV2-10]: Missions list now refers to profiles: requires one or more parameters to run. Use 'profiles help' for instructions, or use the man page. table data
1 parent 2ee7ac1 commit 554adc5

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

components/Gameplay/mission-list.tsx

+53-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,58 @@
11
import { CardTitle, CardDescription, CardHeader, CardContent, CardFooter, Card } from "../ui/card";
22
import Link from "next/link";
33
import { Button } from "../ui/button";
4+
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
5+
import { useEffect, useState } from "react";
46

57
export function MissionList() {
6-
const missions = [
7-
{ name: "Pick your home planet", completed: true },
8+
const supabase = useSupabaseClient();
9+
const session = useSession();
10+
const [profileData, setProfileData] = useState<{ location: any } | null>(null); // Set initial state with the correct type
11+
const [missions, setMissions] = useState([
12+
{ name: "Pick your home planet", completed: false },
813
{ name: "Build your first rover", completed: false },
914
{ name: "Collect your first resources", completed: false },
1015
{ name: "Build your first structure", completed: false },
1116
{ name: "Make your first classification", completed: false },
12-
];
17+
]);
18+
19+
useEffect(() => {
20+
async function fetchProfileData() {
21+
try {
22+
const { data, error } = await supabase
23+
.from("profiles")
24+
.select("location")
25+
.eq("id", session?.user?.id)
26+
.single();
27+
28+
if (error) {
29+
throw error;
30+
};
31+
32+
if (data) {
33+
setProfileData(data);
34+
};
35+
} catch (error) {
36+
console.error("Error fetching profile data:", error.message);
37+
};
38+
};
39+
40+
if (session) {
41+
fetchProfileData();
42+
};
43+
}, [supabase, session]);
44+
45+
useEffect(() => {
46+
// Update the first mission's completion status based on profile location
47+
if (profileData) {
48+
const { location } = profileData;
49+
setMissions((prevMissions) => {
50+
const updatedMissions = [...prevMissions];
51+
updatedMissions[0].completed = [1, 2, 3, 4, 5, 6].includes(location);
52+
return updatedMissions;
53+
});
54+
};
55+
}, [profileData]);
1356

1457
return (
1558
<>
@@ -21,13 +64,11 @@ export function MissionList() {
2164
{missions.map((mission, index) => (
2265
<div key={index} className="flex items-center justify-between">
2366
<div className="flex items-center space-x-3">
24-
<Link href="#">
25-
<LinkIcon
26-
className={`w-5 h-5 text-gray-500 ${
27-
mission.completed ? "line-through" : ""
28-
} hover:text-gray-900 dark:hover:text-gray-50`}
29-
/>
30-
</Link>
67+
<LinkIcon
68+
className={`w-5 h-5 text-gray-500 ${
69+
mission.completed ? "line-through" : ""
70+
} hover:text-gray-900 dark:hover:text-gray-50`}
71+
/>
3172
<p
3273
className={`${
3374
mission.completed ? "line-through text-gray-500 dark:text-gray-400" : ""
@@ -38,8 +79,8 @@ export function MissionList() {
3879
</div>
3980
</div>
4081
))}
41-
</CardContent>
42-
</>
82+
</CardContent>
83+
</>
4384
);
4485
}
4586

pages/tests/onboarding.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PickYourPlanet } from "../../components/Gameplay/Chapter 1/onboarding";
2+
import { MissionList } from "../../components/Gameplay/mission-list";
23
import Layout from "../../components/_Core/Section/Layout";
34

45
export default function OnboardingTest() {
@@ -23,6 +24,7 @@ export default function OnboardingTest() {
2324
`}
2425
</style>
2526
<PickYourPlanet />
27+
<MissionList />
2628
</>
2729
);
2830
};

0 commit comments

Comments
 (0)