diff --git a/components/(scenes)/travel/SolarSystem.tsx b/components/(scenes)/travel/SolarSystem.tsx index 3998dcef..9b93b096 100644 --- a/components/(scenes)/travel/SolarSystem.tsx +++ b/components/(scenes)/travel/SolarSystem.tsx @@ -7,72 +7,43 @@ import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; import { useActivePlanet } from "@/context/ActivePlanet"; import { lidarDataSources, physicsLabDataSources, roverDataSources, telescopeDataSources, zoodexDataSources } from "@/components/Data/ZoodexDataSources"; -const planets = { - solarSystem: [ - { - id: 10, - name: "Mercury", - color: "bg-[#2C3A4A]", - stats: { gravity: "3.7 m/s²", temp: "430°C" }, - anomaly: 10, - planetType: 'Arid', - initialisationMissionId: 100001, - travelTime: '30 seconds', - description: '', - image: '/assets/Planets/Mercury.png', - }, - { - id: 20, - name: "Venus", - color: "bg-yellow-200", - stats: { gravity: "8.87 m/s²", temp: "462°C" }, - anomaly: 20, - planetType: 'Arid', - initialisationMissionId: 200001, - travelTime: '30 seconds', - description: '', - image: '/assets/Planets/Venus.png', - }, - { - id: 69, - name: "Earth", - color: "bg-blue-500", - stats: { gravity: "9.8 m/s²", temp: "15°C" }, - anomaly: 69, - planetType: 'Lush', - initialisationMissionId: 300001, - travelTime: '30 seconds', - description: '', - image: '/assets/Planets/Earth.png', - }, - { - id: 40, - name: "Mars", - color: "bg-red-500", - stats: { gravity: "3.71 m/s²", temp: "-63°C" }, - anomaly: 40, - planetType: 'Arid', - initialisationMissionId: 400001, - travelTime: '30 seconds', - description: '', - image: '/assets/Planets/Mars.png', - }, - ], - exoplanets: [ - // should only show `anomalies` discovered by user - ], +type Exoplanet = { + id: number; + name: string; + distance: number; + anomaly?: number; + planetType?: string; + initialisationMissionId?: number; + image?: string; + description?: string; }; -// ^^ update this to pull from `anomalies` table +type SolarSystemPlanet = { + id: number; + name: string; + color: string; + stats: { + gravity: string; + temp: string; + }; + anomaly: number; + planetType: string; + initialisationMissionId: number; + travelTime: string; + description: string; + image: string; +}; + +type Planet = Exoplanet | SolarSystemPlanet; + export default function SwitchPlanet() { const supabase = useSupabaseClient(); const session = useSession(); + const { activePlanet, updatePlanetLocation } = useActivePlanet(); const [activeTab, setActiveTab] = useState<"solarSystem" | "exoplanets">("solarSystem"); const [currentIndex, setCurrentIndex] = useState(0); - const currentPlanets = planets[activeTab]; - const currentPlanet = currentPlanets[currentIndex]; const [planetStats, setPlanetStats] = useState([]); const [visitedPlanets, setVisitedPlanets] = useState<{ [key: number]: boolean }>({}); @@ -83,6 +54,173 @@ export default function SwitchPlanet() { const [selectedMission, setSelectedMission] = useState(null); const [compatibleMissions, setCompatibleMissions] = useState([]); + const [planets, setPlanets] = useState<{ + solarSystem: SolarSystemPlanet[]; + exoplanets: Exoplanet[]; + }>({ + solarSystem: [ + { + id: 10, + name: "Mercury", + color: "bg-[#2C3A4A]", + stats: { gravity: "3.7 m/s²", temp: "430°C" }, + anomaly: 10, + planetType: 'Arid', + initialisationMissionId: 100001, + travelTime: '30 seconds', + description: '', + image: '/assets/Planets/Mercury.png', + }, + { + id: 20, + name: "Venus", + color: "bg-yellow-200", + stats: { gravity: "8.87 m/s²", temp: "462°C" }, + anomaly: 20, + planetType: 'Arid', + initialisationMissionId: 200001, + travelTime: '30 seconds', + description: '', + image: '/assets/Planets/Venus.png', + }, + { + id: 69, + name: "Earth", + color: "bg-blue-500", + stats: { gravity: "9.8 m/s²", temp: "15°C" }, + anomaly: 69, + planetType: 'Lush', + initialisationMissionId: 300001, + travelTime: '30 seconds', + description: '', + image: '/assets/Planets/Earth.png', + }, + { + id: 40, + name: "Mars", + color: "bg-red-500", + stats: { gravity: "3.71 m/s²", temp: "-63°C" }, + anomaly: 40, + planetType: 'Arid', + initialisationMissionId: 400001, + travelTime: '30 seconds', + description: '', + image: '/assets/Planets/Mars.png', + }, + ], + exoplanets: [], + }); + + const currentPlanets = planets[activeTab]; + const currentPlanet = currentPlanets[currentIndex]; + const planetType = currentPlanet?.planetType || 'Unknown'; + const anomaly = currentPlanet?.anomaly ?? 'Unknown'; + const initialisationMissionId = currentPlanet?.initialisationMissionId ?? null; + const image = currentPlanet?.image ?? '/assets/Planets/DefaultExoplanet.png'; + const description = currentPlanet?.description ?? 'No description available'; + const currentPlanetAnomaly = currentPlanet?.anomaly ?? 0; + + useEffect(() => { + console.log("Component loaded, exoplanets: ", planets.exoplanets); + }, [planets.exoplanets]); + + // Fix for TS error 2345 - ensuring 'number | undefined' doesn't cause an issue + const index = currentPlanet?.anomaly !== undefined ? currentPlanet.anomaly : 0; + + useEffect(() => { + const fetchExoplanets = async () => { + try { + const { data, error } = await supabase + .from("anomalies") + .select("*") + .eq("anomalySet", "tess"); + + if (error) throw error; + + const exoplanetsData = data.map((exoplanet) => ({ + id: exoplanet.id, + name: exoplanet.content, + color: "bg-purple-500", + stats: { gravity: "Unknown", temp: "Unknown" }, + anomaly: exoplanet.id, + planetType: exoplanet.anomalytype || "Unknown", + initialisationMissionId: null, + travelTime: "Unknown", + description: exoplanet.deepnote || "No description available", + image: exoplanet.avatar_url || '/assets/Planets/DefaultExoplanet.png', + })); + + setPlanets((prevState) => ({ + ...prevState, + exoplanets: exoplanetsData as unknown as Exoplanet[], + })); + } catch (error: any) { + console.error("Error fetching exoplanets: ", error.message); + } + }; + + fetchExoplanets(); + }, [supabase]); + + useEffect(() => { + const fetchExoplanets = async () => { + try { + // Fetch all exoplanets from the anomalies table where anomalySet is 'tess' + const { data: exoplanetData, error: exoplanetError } = await supabase + .from("anomalies") + .select("*") + // .eq("anomalySet", "tess"); + .eq("anomalytype", 'planet'); + + if (exoplanetError) throw exoplanetError; + + if (session?.user?.id) { + // Fetch classifications where author is the current user and anomaly is one of the exoplanets + const { data: classificationData, error: classificationError } = await supabase + .from("classifications") + .select("anomaly") + .eq("author", session.user.id) + .in( + "anomaly", + exoplanetData.map((exoplanet) => exoplanet.id) + ); + + if (classificationError) throw classificationError; + + // Extract anomaly IDs (exoplanet IDs) mentioned in classifications + const classifiedExoplanetIds = classificationData.map((classification) => classification.anomaly); + + // Filter exoplanets based on classified exoplanet IDs + const filteredExoplanets = exoplanetData + .filter((exoplanet) => classifiedExoplanetIds.includes(exoplanet.id)) + .map((exoplanet) => ({ + id: exoplanet.id, + name: exoplanet.content, + color: "bg-purple-500", + stats: { gravity: "Unknown", temp: "Unknown" }, + anomaly: exoplanet.id, + planetType: "Frozen", // Set default planet type as Frozen + initialisationMissionId: null, + travelTime: "Unknown", + description: exoplanet.deepnote || "No description available", + image: exoplanet.avatar_url || '/assets/Planets/DefaultExoplanet.png', + })); + + // Update state with the filtered exoplanets + setPlanets((prevState) => ({ + ...prevState, + exoplanets: filteredExoplanets as unknown as Exoplanet[], + })); + } + } catch (error: any) { + console.error("Error fetching exoplanets: ", error.message); + } + }; + + fetchExoplanets(); + }, [supabase, session?.user?.id]); + + useEffect(() => { const fetchVisitedPlanets = async () => { if (!session) return; @@ -266,7 +404,7 @@ export default function SwitchPlanet() { if (!existingInventory || existingInventory.length === 0) { const newConfig = { Uses: 1, - "missions unlocked": [selectedMission?.identifier] + "missions unlocked": [selectedMission?.identifier], }; const inventoryData = { @@ -287,8 +425,11 @@ export default function SwitchPlanet() { } } else { // If the structure exists, update the configuration to add the new mission - const currentConfig = existingInventory[0].configuration || { Uses: 1, "missions unlocked": [] }; - + const currentConfig = existingInventory[0].configuration || { + Uses: 1, + "missions unlocked": [], + }; + // Add the new mission if it doesn't exist in the configuration already const newMission = selectedMission?.identifier; if (!currentConfig["missions unlocked"].includes(newMission)) { @@ -307,12 +448,14 @@ export default function SwitchPlanet() { } } - // Continue with other actions like moving items and updating planet location - await moveItemsToNewPlanet(currentPlanet.anomaly); - updatePlanetLocation(currentPlanet.anomaly); - } - }; + // Ensure anomaly is a valid number + const validAnomaly = currentPlanet?.anomaly ?? 0; + // Use validAnomaly for any function calls that require a number + await moveItemsToNewPlanet(validAnomaly); + updatePlanetLocation(validAnomaly); + } + }; const [missionSelected, setMissionSelected] = useState(false); @@ -339,7 +482,11 @@ export default function SwitchPlanet() { }; }; - const isVisited = classificationsByPlanet[currentPlanet.anomaly]?.length > 0; + const isVisited = currentPlanet?.anomaly !== undefined && classificationsByPlanet[currentPlanet.anomaly]?.length > 0; + const handleTabSwitch = (tab: "solarSystem" | "exoplanets") => { + setActiveTab(tab); + setCurrentIndex(0); + }; return (
@@ -347,13 +494,13 @@ export default function SwitchPlanet() {
diff --git a/components/Layout/Layout.tsx b/components/Layout/Layout.tsx index 8b17444e..f97eda5b 100644 --- a/components/Layout/Layout.tsx +++ b/components/Layout/Layout.tsx @@ -2,8 +2,19 @@ import React, { ReactNode } from "react"; import BottomMenuLayout from "./BottomMenu"; +import { useSession } from "@supabase/auth-helpers-react"; export default function AppLayout({ children }: { children: ReactNode }) { + const session = useSession(); + + if (!session) { + return ( + <> + {children} + + ); + }; + return ( {children} diff --git a/components/Projects/(classifications)/PostForm.tsx b/components/Projects/(classifications)/PostForm.tsx index 65de2a05..1397e589 100644 --- a/components/Projects/(classifications)/PostForm.tsx +++ b/components/Projects/(classifications)/PostForm.tsx @@ -205,7 +205,7 @@ const ClassificationForm: React.FC = ({ anomalyType, an user: session?.user?.id, time_of_completion: new Date().toISOString(), mission: missionNumber, - configuration: null, + configuration: null, }; await supabase.from("missions").insert([missionData]); const newAnomalyData = { diff --git a/components/Projects/Telescopes/ExoplanetC23.tsx b/components/Projects/Telescopes/ExoplanetC23.tsx index 6cd3cb9b..66beffb2 100644 --- a/components/Projects/Telescopes/ExoplanetC23.tsx +++ b/components/Projects/Telescopes/ExoplanetC23.tsx @@ -320,6 +320,21 @@ export function ExoplanetTransitHunter() { ); }; + const missionData = { + user: session?.user.id, + time_of_completion: new Date().toISOString(), + mission: "3000001", + configuration: null, + }; + + const handleCompleteMission = async () => { + try { + await supabase.from("missions").insert([missionData]); + } catch (error: any) { + console.error("Error completing mission: ", error); + }; + }; + // Making the post const handleSubmitClassification = async () => { if (!session || !anomaly) { @@ -327,6 +342,8 @@ export function ExoplanetTransitHunter() { return; }; + handleCompleteMission(); + const planetGeneratorOptions = {}; // Make sure to add mission for completing planet diff --git a/components/Projects/Telescopes/Transiting.tsx b/components/Projects/Telescopes/Transiting.tsx index 93742a5e..06fa7788 100644 --- a/components/Projects/Telescopes/Transiting.tsx +++ b/components/Projects/Telescopes/Transiting.tsx @@ -50,7 +50,7 @@ export function StarterTelescope() { setHasMission3000001(false); } finally { setMissionLoading(false); - } + }; }; checkTutorialMission(); diff --git a/components/Structures/IndividualStructure.tsx b/components/Structures/IndividualStructure.tsx index 211234a5..b07c3d4c 100644 --- a/components/Structures/IndividualStructure.tsx +++ b/components/Structures/IndividualStructure.tsx @@ -167,35 +167,40 @@ const IndividualStructure: React.FC = ({ className="rounded-full p-2 text-[#d8dee9] hover:bg-[#3b4a5a] mt-8" onClick={handleClose} > - Close Modal + Back )} - {/* Dynamic Component Modal */} - {activeComponent && ( - - -
- -
- {activeComponent} -
-
-
- )} +{activeComponent && ( + + +
+ +
+ {activeComponent} +
+
+
+)}
); diff --git a/components/landing.tsx b/components/landing.tsx index 27a69bd4..fa3df0e5 100644 --- a/components/landing.tsx +++ b/components/landing.tsx @@ -14,7 +14,7 @@ export function Landing() {

Star Sailors

-

+

Explore the cosmos & catalogue discoveries in different scientific disciplines

App screenshot
diff --git a/constants/Structures/Properties.tsx b/constants/Structures/Properties.tsx index 66799991..fe6cbc19 100644 --- a/constants/Structures/Properties.tsx +++ b/constants/Structures/Properties.tsx @@ -7,7 +7,7 @@ import AllAutomatonsOnActivePlanet from "@/components/Structures/Auto/AllAutomat import { StarterTelescope } from "@/components/Projects/Telescopes/Transiting"; import { StarterLidar } from "@/components/Projects/Lidar/Clouds"; import { StarterZoodexGallery } from "@/components/Projects/Zoodex/ClassifyOthersAnimals"; -import { BeanIcon, BookAIcon, BookAudioIcon, BookCopy, BookDashedIcon, CameraIcon, CaravanIcon, CloudCogIcon, CogIcon, ConstructionIcon, DogIcon, DotSquare, GemIcon, HeartIcon, LockIcon, LucideSalad, MehIcon, MicroscopeIcon, PenBox, PhoneIcon, PickaxeIcon, PowerIcon, RssIcon, SaladIcon, StarIcon, SunIcon, SwitchCamera, TelescopeIcon, TestTubeDiagonal, TestTubeDiagonalIcon, TreePalmIcon, WebcamIcon } from "lucide-react"; +import { BeanIcon, BookAIcon, BookAudioIcon, BookCopy, BookDashedIcon, CameraIcon, CaravanIcon, CloudCogIcon, CogIcon, ConstructionIcon, DogIcon, DotSquare, EarthIcon, GemIcon, HeartIcon, LockIcon, LucideSalad, MehIcon, MicroscopeIcon, PenBox, PhoneIcon, PickaxeIcon, PowerIcon, RssIcon, SaladIcon, StarIcon, SunIcon, SwitchCamera, TelescopeIcon, TestTubeDiagonal, TestTubeDiagonalIcon, TreePalmIcon, WebcamIcon } from "lucide-react"; import StructureRepair from "@/components/Structures/Config/RepairStructure"; import { RoverPhoto } from "@/content/(anomalies)/(data)/Mars-Photos"; import { AnomalyRoverPhoto } from "@/components/Structures/Auto/AutomatonClassificationShell"; @@ -21,6 +21,7 @@ import LaunchpadStructure from "@/components/Structures/Launchpad/Dashboard"; import CameraComponent from "@/components/Projects/Zoodex/Upload/Camera"; import { PlanktonPortal, PlanktonPortalTutorial } from "@/components/Projects/Zoodex/planktonPortal"; import SwitchPlanet from "@/components/(scenes)/travel/SolarSystem"; +import { ExoplanetTransitHunter } from "@/components/Projects/Telescopes/ExoplanetC23"; interface IndividualStructureProps { name?: string; @@ -144,25 +145,31 @@ export const StructuresConfig: StructureConfig = { icon: , text: "Discover planets", // Transit events, microlensing, etc dynamicComponent: , - sizePercentage: 90, + sizePercentage: 60, showInNoModal: true, }, + { + icon: , + text: "Find new worlds", + dynamicComponent: , + sizePercentage: 80, + }, { icon: , text: "Sunspot data", dynamicComponent: , - sizePercentage: 80, + sizePercentage: 60, }, { icon: , text: "Find early solar systems", dynamicComponent: , - sizePercentage: 80, - }, - { - icon: , - text: "Comets & Asteroids", + sizePercentage: 70, }, + // { + // icon: , + // text: "Comets & Asteroids", + // }, ], }, 3104: { diff --git a/supabase/migrations/20240717135237_remote_schema.sql b/supabase/migrations/20240717135237_remote_schema.sql index 51ecfe55..b0ef1b0a 100644 --- a/supabase/migrations/20240717135237_remote_schema.sql +++ b/supabase/migrations/20240717135237_remote_schema.sql @@ -13,17 +13,23 @@ create table "public"."anomalies" ( "parentAnomaly" bigint -- Add a value for the set the anomaly is in (e.g. expedition) ); -create table "public"."classifications" ( - "id" bigint generated by default as identity not null, - "created_at" timestamp with time zone not null default now(), - "content" text, - "author" uuid, - "anomaly" bigint, - "media" json, - "classificationtype" text, - "classificationConfiguration" jsonb -); - +create table + public.profiles ( + id uuid not null, + updated_at timestamp with time zone null, + username text null, + full_name text null, + avatar_url text null, + website text null, + location bigint null, + "classificationPoints" bigint null, + "playerPathway" text null, + constraint profiles_pkey primary key (id), + constraint profiles_username_key unique (username), + constraint profiles_id_fkey foreign key (id) references auth.users (id) on delete cascade, + constraint profiles_location_fkey foreign key (location) references anomalies (id), + constraint username_length check ((char_length(username) >= 3)) + ) tablespace pg_default; create table "public"."inventory" ( "id" bigint generated by default as identity not null, @@ -36,7 +42,6 @@ create table "public"."inventory" ( "parentItem" bigint ); - create table "public"."missions" ( "id" bigint generated by default as identity not null, "user" uuid, @@ -46,7 +51,6 @@ create table "public"."missions" ( "rewarded_items" bigint[] ); - create table "public"."profiles" ( "id" uuid not null, "updated_at" timestamp with time zone,