Skip to content

Commit

Permalink
🍸🐼 ↝ [SSP-47]: Planet Ids from PH classifications now showing in P4/A…
Browse files Browse the repository at this point in the history
…I4M projects
  • Loading branch information
Gizmotronn committed Jan 9, 2025
1 parent 29bfb4d commit d310b01
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 70 deletions.
2 changes: 2 additions & 0 deletions app/tests/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use client";

import PlanetFour from "@/components/Structures/Missions/Astronomers/SatellitePhotos/P4/PlanetFour";
import React, { useState } from "react";

export default function TestPage() {
return (
// <StarnetLayout>
<>
<PlanetFour />
</>
// {/* </StarnetLayout> */}
);
Expand Down
102 changes: 75 additions & 27 deletions components/Projects/Auto/AI4Mars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useActivePlanet } from "@/context/ActivePlanet";
import ClassificationForm from "../(classifications)/PostForm";
import { Anomaly } from "../Zoodex/ClassifyOthersAnimals";
import ImageAnnotator from "../(classifications)/Annotating/Annotator";
import PreferredTerrestrialClassifications from "@/components/Structures/Missions/PickPlanet";

interface Props {
anomalyid: number | bigint;
Expand Down Expand Up @@ -139,12 +140,18 @@ export function StarterAiForMars({ anomalyid }: Props) {
</div>
</>
)}
</div>
</div>
</div>
);
};

export function AiForMarsProject() {
interface SelectedAnomProps {
anomalyid?: number;
};

export function AiForMarsProject({
anomalyid
}: SelectedAnomProps) {
const supabase = useSupabaseClient();
const session = useSession();
const { activePlanet } = useActivePlanet();
Expand Down Expand Up @@ -183,33 +190,60 @@ export function AiForMarsProject() {
checkTutorialMission();
}, [session, supabase]);

const fetchAnomaly = async () => {
if (!session) {
setLoading(false);
return;
};

try {
const { data: anomalyData, error: anomalyError } = await supabase
.from("anomalies")
.select("*")
.eq("anomalySet", "automaton-aiForMars");

if (anomalyError) throw anomalyError;

const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
setAnomaly(randomAnomaly);
setImageUrl(
`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/telescope/automaton-aiForMars/${randomAnomaly.id}.jpeg`
);
} catch (error: any) {
console.error("Error fetching anomaly", error.message);
setAnomaly(null);
} finally {
setLoading(false);
};
};

useEffect(() => {
async function fetchAnomaly() {
if (!session) {
setLoading(false);
return;
}
// async function fetchAnomaly() {
// if (!session) {
// setLoading(false);
// return;
// };

try {
const { data: anomalyData, error: anomalyError } = await supabase
.from("anomalies")
.select("*")
.eq("anomalySet", "automaton-aiForMars");

if (anomalyError) throw anomalyError;

const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
setAnomaly(randomAnomaly);
setImageUrl(
`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/telescope/automaton-aiForMars/${randomAnomaly.id}.jpeg`
);
} catch (error: any) {
console.error("Error fetching anomaly", error.message);
setAnomaly(null);
} finally {
setLoading(false);
}
}
// try {
// const { data: anomalyData, error: anomalyError } = await supabase
// .from("anomalies")
// .select("*")
// .eq("anomalySet", "automaton-aiForMars");

// if (anomalyError) throw anomalyError;

// const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
// setAnomaly(randomAnomaly);
// setImageUrl(
// `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/telescope/automaton-aiForMars/${randomAnomaly.id}.jpeg`
// );
// } catch (error: any) {
// console.error("Error fetching anomaly", error.message);
// setAnomaly(null);
// } finally {
// setLoading(false);
// }
// }

fetchAnomaly();
}, [session, supabase]);
Expand Down Expand Up @@ -254,6 +288,7 @@ export function AiForMarsProject() {
/> */}
</>
)}
<p>Selected Anomaly ID: {anomalyid}</p>
<button
onClick={startTutorial}
className="mt-4 px-4 py-2 bg-[#85DDA2] text-[#2C3A4A] rounded-md shadow-md"
Expand All @@ -264,4 +299,17 @@ export function AiForMarsProject() {
)}
</div>
);
};

export function AI4MWrapper() {
const [selectedAnomaly, setSelectedAnomaly] = useState<number | null>(null);

return (
<div className="space-y-8">
<PreferredTerrestrialClassifications onSelectAnomaly={setSelectedAnomaly} />
{selectedAnomaly &&
<AiForMarsProject anomalyid={selectedAnomaly}
/>}
</div>
);
};
68 changes: 34 additions & 34 deletions components/Projects/Satellite/PlanetFour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,43 +157,43 @@ export function PlanetFourProject({ anomalyid }: SelectedAnomProps) {
const handleShowTutorial = () => {
setShowTutorial(true);
};
useEffect(() => {
const fetchAnomaly = async () => {
if (!hasMission20000005 || !session) return;

try {
const { data: anomalyData, error: anomalyError } = await supabase
.from('anomalies')
.select('*')
.eq('anomalySet', 'satellite-planetFour');

if (anomalyError) throw anomalyError;
const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
setAnomaly(randomAnomaly);
setImageUrl(`${supabaseUrl}/storage/v1/object/public/telescope/satellite-planetFour/${randomAnomaly.id}.jpeg`);
} catch (error: any) {
console.error("Error fetching anomaly", error.message);
setAnomaly(null);
} finally {
setLoading(false);
}

const fetchAnomaly = async () => {
if (!anomalyid || !session) return;

setLoading(true);

try {
const { data: anomalyData, error: anomalyError } = await supabase
.from('anomalies')
.select('*')
.eq('id', anomalyid)
.single();

if (anomalyError) throw anomalyError;

setAnomaly(anomalyData);
setImageUrl(`${supabaseUrl}/storage/v1/object/public/telescope/satellite-planetFour/${anomalyData.id}.jpeg`);
} catch (error: any) {
console.error("Error fetching anomaly", error.message);
setAnomaly(null);
} finally {
setLoading(false);
};

if (hasMission20000005 && session) {
fetchAnomaly();
}
}, [session, supabase, supabaseUrl, hasMission20000005]);
};

useEffect(() => {
fetchAnomaly();
}, [anomalyid, session, supabase, supabaseUrl]);

if (loading) {
return <div><p>Loading...</p></div>;
};

if (!anomaly) {
return <div><p>No anomaly found.</p></div>;
return <div><p>No anomaly found with ID {anomalyid}</p></div>;
};

return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg overflow-y-auto max-h-[90vh] rounded-lg">
{!showTutorial ? (
Expand All @@ -206,7 +206,7 @@ export function PlanetFourProject({ anomalyid }: SelectedAnomProps) {
</Button>
{imageUrl && (
<ImageAnnotator
anomalyId={anomaly?.id.toString() || ""}
anomalyId={anomaly.id.toString()}
anomalyType="satellite-planetFour"
missionNumber={200000052}
assetMentioned={imageUrl}
Expand All @@ -218,10 +218,10 @@ export function PlanetFourProject({ anomalyid }: SelectedAnomProps) {
</>
) : (
<div>
<StarterPlanetFour anomalyid={anomaly?.id} />
<StarterPlanetFour anomalyid={anomaly.id} />
</div>
)}
{anomalyid && <p>Selected Anomaly: {anomalyid}</p>}
<p>Selected Anomaly ID: {anomalyid}</p>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react";
import MissionShell from "../../../BasePlate";
import { CloudCogIcon, FolderCog, PaintBucket, Vote } from "lucide-react";
import { AiForMarsProject } from "@/components/Projects/Auto/AI4Mars";
import { AI4MWrapper, AiForMarsProject } from "@/components/Projects/Auto/AI4Mars";
import VoteAI4MClassifications from "./AI4MVote";

interface Mission {
Expand Down Expand Up @@ -40,7 +40,7 @@ const AI4M = () => {
icon: CloudCogIcon,
points: 2,
completedCount: 0,
internalComponent: () => <AiForMarsProject />,
internalComponent: () => <AI4MWrapper />,
color: "text-blue-500",
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Mission {

interface MissionPoints {
[key: number]: number;
};
};

const PlanetFour = () => {
const supabase = useSupabaseClient();
Expand Down
12 changes: 6 additions & 6 deletions components/Structures/Missions/PickPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Classification {

interface PreferredTerrestrialClassificationsProps {
onSelectAnomaly: (anomalyId: number | null) => void;
}
};

export default function PreferredTerrestrialClassifications({
onSelectAnomaly,
Expand Down Expand Up @@ -46,7 +46,7 @@ interface PreferredTerrestrialClassificationsProps {
if (classificationIds.length === 0) {
setClassifications([]);
return;
}
};

const { data: classificationsData, error: classificationsError } = await supabase
.from("classifications")
Expand All @@ -62,8 +62,8 @@ interface PreferredTerrestrialClassificationsProps {
images = classification.media.filter((url: any) => typeof url === "string");
} else if (typeof classification.media === "object" && classification.media.uploadUrl) {
images.push(classification.media.uploadUrl);
}
}
};
};
return { ...classification, images };
});

Expand All @@ -72,7 +72,7 @@ interface PreferredTerrestrialClassificationsProps {
setError("An unexpected error occurred.");
} finally {
setLoading(false);
}
};
};

useEffect(() => {
Expand All @@ -98,7 +98,7 @@ interface PreferredTerrestrialClassificationsProps {
votes={0}
category="Terrestrial"
tags={["Preferred", "Planet"]}
images={classification.images || []}
images={classification.media || []}
anomalyId={classification.anomaly?.toString() || "N/A"}
classificationType="planet"
classificationConfig={classification.classificationConfiguration}
Expand Down

0 comments on commit d310b01

Please sign in to comment.