diff --git a/app/planets/[id]/page.tsx b/app/planets/[id]/page.tsx index bd4271ba..5fac6631 100644 --- a/app/planets/[id]/page.tsx +++ b/app/planets/[id]/page.tsx @@ -22,7 +22,7 @@ interface Classification { tags?: string[]; images?: string[]; relatedClassifications?: Classification[]; -} +}; type Anomaly = { id: number; diff --git a/app/tests/page.tsx b/app/tests/page.tsx index 5079c958..de591cdb 100644 --- a/app/tests/page.tsx +++ b/app/tests/page.tsx @@ -3,11 +3,12 @@ import { FullPlanetGenerator } from "@/components/Data/Generator/Astronomers/PlanetHunters/V2/full-planet-generator"; import { SimplePlanetGenerator } from "@/components/Data/Generator/Astronomers/PlanetHunters/Simple/simple-planet-generator"; import FileOrWebcamUpload from "@/components/Projects/Zoodex/Upload/GptClassification"; +import { ClickACoral } from "@/components/Projects/Zoodex/click-a-coral"; export default function TestPage() { return (
- +
); }; diff --git a/components/Projects/Zoodex/click-a-coral.tsx b/components/Projects/Zoodex/click-a-coral.tsx new file mode 100644 index 00000000..ac1bdf2f --- /dev/null +++ b/components/Projects/Zoodex/click-a-coral.tsx @@ -0,0 +1,111 @@ +'use client'; + +import React, { useEffect, useState } from "react"; +import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react"; +import { useActivePlanet } from "@/context/ActivePlanet"; +import ClassificationForm from "../(classifications)/PostForm"; +import { Anomaly } from "../Telescopes/Transiting"; + +interface ZoodexProps { + anomalyid: string; +}; + +export function ClickACoral() { + const supabase = useSupabaseClient(); + const session = useSession(); + + const { activePlanet } = useActivePlanet(); + + const [anomaly, setAnomaly] = useState(null); + const [imageUrl, setImageUrl] = useState(null); + const [showTutorial, setShowTutorial] = useState(false); + + const [loading, setLoading] = useState(true); + + useEffect(() => { + async function fetchAnomaly() { + if (!session) { + setLoading(false); + return; + }; + + try { + const { data: anomalyData, error: anomalyError } = await supabase + .from("anomalies") + .select("*") + .eq("anomalySet", "zoodex-clickACoral") + + if (anomalyError) { + throw anomalyError; + }; + + if (!anomalyData) { + setAnomaly(null); + setLoading(false); + return; + }; + + const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)]; + setAnomaly(randomAnomaly); + + const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; + setImageUrl(`${supabaseUrl}/storage/v1/object/public/zoodex/zoodex-clickACoral/${randomAnomaly.id}.png`); + } catch (error: any) { + console.error(error); + setLoading(false); + } finally { + setLoading(false); + }; + }; + + fetchAnomaly(); + }, [session, supabase, activePlanet]); + + if (loading) { + return ( +
+

Loading...

+
+ ); + }; + + if (!anomaly) { + return ( +
+

The owls are sleeping, try again later

+
+ ); + }; + + return ( +
+
+
+ + + {/* {showTutorial && anomaly && } */} + + {!showTutorial && ( + <> + {anomaly.content} + +

{imageUrl}

+ + + )} +
+
+
+ ); +}; \ No newline at end of file diff --git a/types/Annotation.tsx b/types/Annotation.tsx index abb27947..2d5cfd82 100644 --- a/types/Annotation.tsx +++ b/types/Annotation.tsx @@ -42,6 +42,8 @@ export const P4CATEGORIES: Record = { }, }; +export type CACCategory = 'antipathes atlantica'; + export type PHCategory = 'Noise' | 'Clear dip' | 'Missing' | 'Custom'; export const PHCATEGORIES: Record = { Noise: {