diff --git a/app/tests/missionsUnlocked.tsx b/app/tests/missionsUnlocked.tsx deleted file mode 100644 index 82cab240..00000000 --- a/app/tests/missionsUnlocked.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { useEffect, useState } from "react"; -import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react"; - -interface InventoryItem { - id: number; - configuration: { - "missions unlocked"?: string[]; - [key: string]: any; // Allow other properties in configuration - }; -} - -const UserMissions = () => { - const supabase = useSupabaseClient(); - const session = useSession(); - - const [missions, setMissions] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - useEffect(() => { - if (!session?.user) return; - - const fetchUserMissions = async () => { - setLoading(true); - setError(null); - - try { - // Query inventory for items owned by the user and containing missions unlocked - const { data, error } = await supabase - .from("inventory") - .select("id, configuration") - .eq("owner", session.user.id) - .not("configuration->missions unlocked", "is", null); // Ensure "missions unlocked" exists - - if (error) throw error; - - // Extract and deduplicate all "missions unlocked" - const unlockedMissions = data - ?.flatMap((item: InventoryItem) => item.configuration["missions unlocked"] || []) - .filter((mission: string) => mission); // Filter out empty values - - const uniqueMissions = Array.from(new Set(unlockedMissions)); - - setMissions(uniqueMissions); - } catch (err) { - console.error("Error fetching user missions:", err); - setError("Failed to fetch missions. Please try again."); - } finally { - setLoading(false); - } - }; - - fetchUserMissions(); - }, [session?.user, supabase]); - - if (!session?.user) return

Please log in to see your missions.

; - - if (loading) return

Loading missions...

; - - if (error) return

{error}

; - - if (missions.length === 0) { - return

No missions unlocked yet.

; - } - - return ( -
-

Missions Unlocked

-
    - {missions.map((mission, index) => ( -
  • - {mission} -
  • - ))} -
-
- ); -}; - -export default UserMissions; \ No newline at end of file diff --git a/app/tests/page.tsx b/app/tests/page.tsx index 2defbe67..085a16fb 100644 --- a/app/tests/page.tsx +++ b/app/tests/page.tsx @@ -1,12 +1,9 @@ "use client"; -import PlanetFour from "@/components/Structures/Missions/Astronomers/SatellitePhotos/P4/PlanetFour"; - export default function TestPage() { return ( // <> - {/* */} // {/* */} ); diff --git a/components/(scenes)/planetScene/bigMap.tsx b/components/(scenes)/planetScene/bigMap.tsx deleted file mode 100644 index e4e06e6b..00000000 --- a/components/(scenes)/planetScene/bigMap.tsx +++ /dev/null @@ -1,320 +0,0 @@ -import { useState, useEffect } from 'react'; -import { TopographicMap } from '../mining/topographic-map'; -import { MineralDeposit } from '../mining/mineral-deposit-list'; -import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react'; -import { useActivePlanet } from '@/context/ActivePlanet'; -import { TerrainMap } from '../mining/terrain-map'; - -type Landmark = { - id: string; - name: string; - description: string; - position: { x: number; y: number }; - isOpen: boolean; -}; - -type Anomaly = { - id: number; - anomalytype: string; - content: string | null; - configuration: object | null; -}; - -export default function BigMap() { - const supabase = useSupabaseClient(); - const session = useSession(); - - const { activePlanet } = useActivePlanet(); - - const [landmarks, setLandmarks] = useState<{ [anomalyId: string]: Landmark[] }>({}); - const [mineralDeposits, setMineralDeposits] = useState([]); - const [activeMap, setActiveMap] = useState<'2D' | '3D'>('2D'); - - const [mentionedAnomalies, setMentionedAnomalies] = useState([]); - - useEffect(() => { - const fetchLandmarks = async () => { - if (!session?.user?.id) return; - - try { - // Fetch classifications for user to get anomalies they worked on - const { data: classificationData, error: classificationError } = await supabase - .from('classifications') - .select('anomaly') - .eq('author', session.user.id); - - if (classificationError) { - console.error('Error fetching classifications:', classificationError); - return; - } - - const anomalyIds = classificationData?.map((c) => c.anomaly) || []; - if (!anomalyIds.length) { - console.log('No anomalies found for user.'); - setMentionedAnomalies([]); - return; - } - - // Fetch anomaly details - const { data: anomaliesData, error: anomaliesError } = await supabase - .from('anomalies') - .select('*') - .in('id', anomalyIds); - - if (anomaliesError) { - console.error('Error fetching anomalies:', anomaliesError); - return; - } - setMentionedAnomalies(anomaliesData || []); - - const landmarksByAnomaly: { [key: number]: Landmark[] } = {}; - for (const anomalyId of anomalyIds) { - const { data: inventoryData, error: inventoryError } = await supabase - .from('inventory') - .select('id, item, quantity') - .eq('owner', session.user.id) - .eq('anomaly', anomalyId) - .gt('quantity', 0); - - if (inventoryError) { - console.error(`Error fetching inventory for anomaly ${anomalyId}:`, inventoryError); - continue; - } - - const res = await fetch('/api/gameplay/inventory'); - const items = await res.json(); - - const structures = inventoryData - ?.filter((inventoryItem) => - items.some( - (item: { id: number; ItemCategory: string }) => - item.id === inventoryItem.item && item.ItemCategory === 'Structure' - ) - ) - .map((inventoryItem) => { - const itemDetails = items.find((item: { id: number }) => item.id === inventoryItem.item); - return { - id: inventoryItem.id.toString(), - name: itemDetails?.name || 'Unknown', - description: itemDetails?.description || 'No description available', - position: itemDetails?.position || { x: Math.random() * 100, y: Math.random() * 100 }, - isOpen: false, - }; - }); - - landmarksByAnomaly[anomalyId] = structures || []; - } - - setLandmarks(landmarksByAnomaly); - } catch (error) { - console.error('Error fetching landmarks:', error); - } - }; - - fetchLandmarks(); - }, [session, supabase]); - - useEffect(() => { - const fetchDepositsAndInventory = async () => { - if (!session?.user?.id || !activePlanet?.id) { - console.error("User or activePlanet is undefined."); - return; - }; - - const { data: deposits, error: depositsError } = await supabase - .from("mineralDeposits") - .select("id, mineralconfiguration") - .eq("owner", session?.user.id) - .eq("anomaly", activePlanet?.id); - - if (depositsError) { - console.error("Error fetching mineral deposits:", depositsError); - return; - } - - const formattedDeposits = deposits?.map((deposit, index) => ({ - id: `${deposit.id}-${index}`, // Ensure uniqueness - name: deposit.mineralconfiguration.mineral || "Unknown", - mineral: deposit.mineralconfiguration.mineral || "Unknown", - amount: deposit.mineralconfiguration.quantity || 0, - icon_url: deposit.mineralconfiguration.icon_url || "", - level: deposit.mineralconfiguration.level || 1, - uses: deposit.mineralconfiguration.uses || [], - position: deposit.mineralconfiguration.position || { x: 50, y: 50 }, - })); - - setMineralDeposits(formattedDeposits || []); - - const { data: inventoryData, error: inventoryError } = await supabase - .from("inventory") - .select("id, item, quantity") - .eq("owner", session?.user.id) - .eq("anomaly", activePlanet?.id) - .gt("quantity", 0); - - if (inventoryError) { - console.error("Error fetching inventory:", inventoryError); - return; - } - - const res = await fetch('/api/gameplay/inventory'); - const items = await res.json(); - - const structures = inventoryData - ?.filter((inventoryItem) => - items.some( - (item: { id: any; ItemCategory: string; }) => - item.id === inventoryItem.item && - item.ItemCategory === "Structure" - ) - ) - .map((inventoryItem) => { - const itemDetails = items.find( - (item: { id: any; }) => item.id === inventoryItem.item - ); - return { - id: inventoryItem.id.toString(), - name: itemDetails?.name || "Unknown", - description: itemDetails?.description || "", - amount: inventoryItem.quantity || 0, - icon_url: itemDetails?.icon_url || "", - locationType: itemDetails?.locationType || "Unknown", - }; - }); - }; - - fetchDepositsAndInventory(); - }, [session, activePlanet, supabase]); - - const [activeLandmark, setActiveLandmark] = useState(null); - - const handleLandmarkClick = (id: string) => { - console.log("Landmark clicked:", id); - const landmark = Object.values(landmarks).flat().find((l: Landmark) => l.id === id); - if (landmark) { - setActiveLandmark({ ...landmark, isOpen: true }); - } - }; - - const toggleMap = () => { - setActiveMap((prev) => (prev === '2D' ? '3D' : '2D')); - setLandmarks((prev) => ({ ...prev })); - setActiveLandmark(null); - }; - - const closeModal = () => { - if (activeLandmark) { - setLandmarks((prevLandmarks) => { - const updatedLandmarks = { ...prevLandmarks }; - if (activeLandmark) { - updatedLandmarks[activeLandmark.id] = updatedLandmarks[activeLandmark.id]?.map((landmark) => - landmark.id === activeLandmark.id - ? { ...landmark, isOpen: false } - : landmark - ) || []; - } - return updatedLandmarks; - }); - setActiveLandmark(null); - } - }; - - useEffect(() => { - const fetchAnomaliesForUser = async () => { - if (!session?.user?.id) { - console.error("User is not authenticated."); - return; - } - - try { - const { data: classificationData, error: classificationError } = - await supabase - .from("classifications") - .select("anomaly") - .eq("author", session.user.id); - - if (classificationError) { - console.error("Error fetching classifications:", classificationError); - return; - } - - const anomalyIds = classificationData - ?.map((classification) => classification.anomaly) - .filter(Boolean); - - if (!anomalyIds?.length) { - console.log("No anomalies mentioned by the user."); - setMentionedAnomalies([]); - return; - } - - // Fetch details for the mentioned anomalies - const { data: anomaliesData, error: anomaliesError } = await supabase - .from("anomalies") - .select("*") - .in("id", anomalyIds); - - if (anomaliesError) { - console.error("Error fetching anomalies:", anomaliesError); - return; - } - - setMentionedAnomalies(anomaliesData || []); - } catch (error) { - console.error("Unexpected error:", error); - } - }; - - fetchAnomaliesForUser(); - }, [session, supabase]); - - return ( -
-
-
-

Big Map

- -
-
- {mentionedAnomalies.map((anomaly) => ( -
-

{anomaly.id}

- {activeMap === "2D" ? ( - { - console.log(`Clicked landmark on anomaly ${anomaly.id}`); - }} - onDepositSelect={() => { - console.log(`Selected deposit on anomaly ${anomaly.id}`); - }} - /> - ) : ( - { - console.log(`Clicked landmark on anomaly ${anomaly.id}`); - }} - /> - )} -
- ))} -
-
-
- ); -}; \ No newline at end of file diff --git a/components/(scenes)/planetScene/initialisePlanet.tsx b/components/(scenes)/planetScene/initialisePlanet.tsx deleted file mode 100644 index 489552b6..00000000 --- a/components/(scenes)/planetScene/initialisePlanet.tsx +++ /dev/null @@ -1,93 +0,0 @@ -"use client"; - -import React, { useEffect, useState } from "react"; -import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react"; - -interface Mission { - id: number; - name: string; - anomaly: number; -}; - -interface InitialisePlanetProps { - planetId: number; -}; - -export default function InitialisePlanet({ planetId }: InitialisePlanetProps) { - const supabase = useSupabaseClient(); - const session = useSession(); - - const [mission, setMission] = useState(null); - const [loading, setLoading] = useState(true); - const [hasMission, setHasMission] = useState(false); - - useEffect(() => { - const fetchMission = async () => { - const response = await fetch('/api/gameplay/missions/planets/initialisation'); - const missions: Mission[] = await response.json(); - - const foundMission = missions.find(m => m.anomaly === planetId); - setMission(foundMission || null); - setLoading(false); - }; - - fetchMission(); - }, [planetId]); - - useEffect(() => { - const checkExistingMission = async () => { - if (!session || !mission) return; - - const { data, error } = await supabase - .from("missions") - .select("*") - .eq("user", session.user.id) - .eq("mission", mission.id); - - if (error) { - console.error('Error checking existing missions: ', error.message); - return; - }; - - setHasMission(data && data.length > 0); - }; - - checkExistingMission(); - }, [session, mission]); - - const handleInitialisePlanet = async () => { - if (!session || !mission) return; - - const { error } = await supabase - .from("missions") - .insert([{ user: session.user.id, mission: mission.id }]); - - if (error) { - console.error('Error creating mission: ', error.message); - } else { - console.log('Planet initialized successfully'); - setHasMission(true) - }; - }; - - if (loading) { - return

Loading...

; - }; - - if (!mission) { - return

No mission found for this planet.

; - }; - - if (hasMission) { - return null; - }; - - return ( - - ); -}; \ No newline at end of file diff --git a/content/Classifications/Options.ts b/content/Classifications/Options.ts index 2100caff..a16f8fcc 100644 --- a/content/Classifications/Options.ts +++ b/content/Classifications/Options.ts @@ -137,6 +137,34 @@ export const roverImgClassificationOptions: ClassificationOption[] = [ { id: 6, text: 'Sandy/rocky terrain' }, ]; +export const initialCloudClassificationOptions: ClassificationOption[] = [ + { + id: 1, + text: "Narrow arch", + }, + { + id: 2, + text: "Wide arch", + }, + { + id: 3, + text: "1 cloud", + }, + { + id: 4, text: "2 clouds", + }, + { + id: 5, text: "3 clouds", + }, + { + id: 6, text: "4+ clouds", + }, +]; + + + + + export const lidarEarthCloudsReadClassificationOptions: ClassificationOption[] = [ { id: 1, @@ -261,30 +289,6 @@ export const penguinWatchClassificationOptions: ClassificationOption[] = [ }, ]; -export const initialCloudClassificationOptions: ClassificationOption[] = [ - { - id: 1, - text: "Narrow arch", - }, - { - id: 2, - text: "Wide arch", - }, - { - id: 3, - text: "1 cloud", - }, - { - id: 4, text: "2 clouds", - }, - { - id: 5, text: "3 clouds", - }, - { - id: 6, text: "4+ clouds", - }, -]; - export const zoodexBurrowingOwlClassificationOptions: ClassificationOption[] = [ { id: 1,