Skip to content

Commit 0d63c4a

Browse files
committed
🪂🪖 ↝ [SSM-61 SSM-63 SSM-62 SSC-30]: Each mission in comp. now has a modal and react node comp
1 parent 5b2db84 commit 0d63c4a

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

components/Layout/Guide.tsx

+43-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { motion, AnimatePresence } from "framer-motion";
55
import { ChevronLeft, ChevronRight, HelpCircle, Expand, Telescope, TreeDeciduous, CloudHail, LightbulbIcon, LucideTestTubeDiagonal, CameraIcon, Shapes, PersonStandingIcon } from "lucide-react";
66
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
77
import { useActivePlanet } from "@/context/ActivePlanet";
8+
import MissionInfoModal from "../Missions/MissionInfoModal";
9+
import AllClassifications from "@/content/Starnet/YourClassifications";
810

9-
interface Mission {
11+
export interface Mission {
1012
id: number | number[];
1113
name: string;
1214
description: string;
@@ -16,6 +18,7 @@ interface Mission {
1618
tableEntry?: string;
1719
tableColumn?: string;
1820
voteOn?: string;
21+
modalContent?: React.ReactNode;
1922
};
2023

2124
interface DialogueStep {
@@ -106,6 +109,7 @@ const globalMissions: Mission[] = [
106109
tableEntry: 'votes',
107110
tableColumn: 'user_id',
108111
voteOn: 'planet',
112+
modalContent: <AllClassifications initialType="planet" />,
109113
},
110114
];
111115

@@ -127,6 +131,17 @@ const StructureMissionGuide = () => {
127131
{ missions: meteorologyMissions, name: 'Meteorologist' },
128132
];
129133

134+
// For modals
135+
const [selectedMission, setSelectedMission] = useState<Mission | null>(null);
136+
137+
const handleMissionClick = (mission: Mission) => {
138+
setSelectedMission(mission);
139+
};
140+
141+
const closeModal = () => {
142+
setSelectedMission(null);
143+
};
144+
130145
useEffect(() => {
131146
async function fetchInventoryAndCompletedMissions() {
132147
if (!session?.user?.id || !activePlanet?.id) return;
@@ -221,8 +236,9 @@ const StructureMissionGuide = () => {
221236

222237
setScrollableMissions(uniqueMissions);
223238
}, [currentCategory, ownedItems]);
224-
225-
239+
240+
const [modalMissionContent, setModalMissionContent] = useState<React.ReactNode>(null);
241+
const [isModalOpen, setIsModalOpen] = useState(false);
226242

227243
useEffect(() => {
228244
const currentMissions = categories[currentCategory].missions;
@@ -246,16 +262,33 @@ const StructureMissionGuide = () => {
246262
setScrollableMissions(uniqueMissions);
247263
}, [currentCategory, ownedItems]);
248264

265+
const nextCategory = () => {
266+
setCurrentCategory((prev) => (prev + 1) % categories.length);
267+
};
268+
269+
const previousCategory = () => {
270+
setCurrentCategory((prev) => (prev - 1 + categories.length) % categories.length);
271+
};
272+
249273
const renderMission = (mission: Mission) => {
250274
const missionId = Array.isArray(mission.id) ? mission.id[0] : mission.id;
251275
const isCompleted = completedMissions.includes(missionId);
252276

277+
const handleMissionClick = () => {
278+
setModalMissionContent(mission.modalContent);
279+
setIsModalOpen(true);
280+
};
281+
253282
return (
254-
<Card key={missionId} className={`cursor-pointer border mb-2 ${isCompleted ? 'bg-gray-700' : 'bg-gray-800'}`}>
283+
<Card
284+
key={missionId}
285+
className={`cursor-pointer border mb-2 ${isCompleted ? "bg-gray-700" : "bg-gray-800"}`}
286+
onClick={handleMissionClick}
287+
>
255288
<CardContent className="p-4 flex items-center space-x-4">
256289
<mission.icon className={`w-8 h-8 ${mission.color}`} />
257290
<div>
258-
<h3 className={`text-lg font-semibold ${isCompleted ? 'text-green-500 line-through' : 'text-gray-200'}`}>
291+
<h3 className={`text-lg font-semibold ${isCompleted ? "text-green-500 line-through" : "text-gray-200"}`}>
259292
{mission.name}
260293
</h3>
261294
<p className={`text-sm ${isCompleted ? 'text-green-400' : 'text-gray-400'}`}>
@@ -267,14 +300,6 @@ const StructureMissionGuide = () => {
267300
);
268301
};
269302

270-
const nextCategory = () => {
271-
setCurrentCategory((prev) => (prev + 1) % categories.length);
272-
};
273-
274-
const previousCategory = () => {
275-
setCurrentCategory((prev) => (prev - 1 + categories.length) % categories.length);
276-
};
277-
278303
return (
279304
<div className="p-4 max-w-6xl mx-auto font-mono">
280305
<div className="relative bg-gradient-to-r from-gray-900 via-gray-800 to-gray-900 border-2 border-gray-700">
@@ -299,6 +324,11 @@ const StructureMissionGuide = () => {
299324
</AnimatePresence>
300325
</CardContent>
301326
</div>
327+
<MissionInfoModal
328+
show={isModalOpen}
329+
onClose={() => setIsModalOpen(false)}
330+
content={modalMissionContent}
331+
/>
302332
</div>
303333
);
304334
};
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useEffect, useState } from "react";
2+
import { Button } from "../ui/button";
3+
4+
const MissionInfoModal = ({
5+
show,
6+
onClose,
7+
content,
8+
}: {
9+
show: boolean;
10+
onClose: () => void;
11+
content: React.ReactNode;
12+
}) => {
13+
if (!show) return null;
14+
15+
return (
16+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-90">
17+
<div className="w-full h-full flex flex-col p-6 overflow-auto">
18+
{/* Close button */}
19+
<Button
20+
onClick={onClose}
21+
className="absolute top-4 right-4 bg-red-600 text-white text-lg font-bold hover:bg-red-700 focus:ring-2 focus:ring-red-400 focus:outline-none"
22+
>
23+
Close ✖
24+
</Button>
25+
{/* Content */}
26+
<div className="flex-grow flex items-center justify-center text-gray-200">
27+
{content}
28+
</div>
29+
</div>
30+
</div>
31+
);
32+
};
33+
34+
export default MissionInfoModal;

0 commit comments

Comments
 (0)