diff --git a/components/Projects/(classifications)/Annotating/Annotator.tsx b/components/Projects/(classifications)/Annotating/Annotator.tsx index 011762f3..d88660d3 100644 --- a/components/Projects/(classifications)/Annotating/Annotator.tsx +++ b/components/Projects/(classifications)/Annotating/Annotator.tsx @@ -2,7 +2,7 @@ import { useRef, useState } from 'react'; import { Button } from '@/components/ui/button'; -import { Download, Upload } from 'lucide-react'; +import { Download } from 'lucide-react'; import { ImageUploader } from './ImageUploader'; import { DrawingCanvas } from './DrawingCanvas'; import { DrawingControls } from './DrawingControls'; @@ -10,8 +10,8 @@ import { downloadAnnotatedImage } from './DrawingUtils'; import type { Point, Line, Shape, DrawingMode } from '@/types/Annotation'; import { useToast } from "@/hooks/toast"; -export function ImageAnnotator() { - const [imageUrl, setImageUrl] = useState(null); +export function ImageAnnotator({ initialImageUrl }: { initialImageUrl?: string }) { + const [imageUrl, setImageUrl] = useState(initialImageUrl || null); const [isDrawing, setIsDrawing] = useState(false); const [currentLine, setCurrentLine] = useState({ points: [], color: '#ff0000', width: 2 }); const [currentShape, setCurrentShape] = useState(null); @@ -104,10 +104,10 @@ export function ImageAnnotator() { }); return; } - + setIsDownloading(true); try { - await downloadAnnotatedImage(svgRef.current, imageRef.current); + await downloadAnnotatedImage(svgRef.current, imageRef.current, { returnBlob: true }); toast({ title: "Success", description: "Image downloaded successfully", @@ -121,13 +121,16 @@ export function ImageAnnotator() { } finally { setIsDownloading(false); } - }; + }; return (
-
+ {!initialImageUrl && !imageUrl && ( - {imageUrl && ( + )} + + {imageUrl && ( + <> - )} -
- - {imageUrl && ( - <> -

Upload an image to begin annotating

)} ); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/components/Projects/(classifications)/Annotating/DrawingUtils.tsx b/components/Projects/(classifications)/Annotating/DrawingUtils.tsx index 9703cd70..5c0055b5 100644 --- a/components/Projects/(classifications)/Annotating/DrawingUtils.tsx +++ b/components/Projects/(classifications)/Annotating/DrawingUtils.tsx @@ -50,9 +50,7 @@ export const getMousePosition = ( }; export const downloadAnnotatedImage = async ( - svgElement: SVGSVGElement, - imageElement: HTMLImageElement -): Promise => { +svgElement: SVGSVGElement, imageElement: HTMLImageElement, p0: { returnBlob: boolean; }): Promise => { // Create canvas with the correct dimensions const canvas = document.createElement('canvas'); const width = imageElement.naturalWidth; diff --git a/components/Projects/Auto/AI4Mars.tsx b/components/Projects/Auto/AI4Mars.tsx index 90311b5e..991a6e86 100644 --- a/components/Projects/Auto/AI4Mars.tsx +++ b/components/Projects/Auto/AI4Mars.tsx @@ -4,8 +4,9 @@ import React, { useState, useEffect } from "react"; import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; import { useActivePlanet } from "@/context/ActivePlanet"; import ClassificationForm from "../(classifications)/PostForm"; - import { Anomaly } from "../Zoodex/ClassifyOthersAnimals"; +import { ImageAnnotator } from "../(classifications)/Annotating/Annotator"; + interface Props { anomalyid: number | bigint; }; @@ -16,6 +17,7 @@ export function StarterAiForMars({ anomalyid }: Props) { const [part, setPart] = useState(1); const [line, setLine] = useState(1); + const nextLine = () => setLine(prevLine => prevLine + 1); const nextPart = () => { setPart(2); @@ -145,87 +147,80 @@ export function StarterAiForMars({ anomalyid }: Props) { export function AiForMarsProject() { const supabase = useSupabaseClient(); const session = useSession(); - const { activePlanet } = useActivePlanet(); const [anomaly, setAnomaly] = useState(null); - const [showTutorial, setShowTutorial] = useState(false); + const [showTutorial, setShowTutorial] = useState(false); const [imageUrl, setImageUrl] = useState(null); + const [loading, setLoading] = useState(true); + const [hasMission20000006, setHasMission20000006] = useState(null); - const [loading, setLoading] = useState(true); + useEffect(() => { + const checkTutorialMission = async () => { + if (!session) return; - const [hasMission20000006, setHasMission20000006] = useState(null); + try { + const { data: missionData, error: missionError } = await supabase + .from("missions") + .select("id") + .eq("user", session.user.id) + .eq("mission", "20000006") + .limit(1); + + if (missionError) { + console.error("Error fetching mission data:", missionError); + setHasMission20000006(false); + return; + } + + setHasMission20000006(missionData && missionData.length > 0); + } catch (error) { + console.error("Error checking user mission: ", error); + setHasMission20000006(false); + } + }; + + checkTutorialMission(); + }, [session, supabase]); - // useEffect(() => { - // const checkTutorialMission = async () => { - // if (!session) return; - - // try { - // const { data: missionData, error: missionError } = await supabase - // .from('missions') - // .select('id') - // .eq('user', session.user.id) - // .eq('mission', '20000006') - // .limit(1); - - // if (missionError) { - // console.error("Error fetching mission data:", missionError); - // setHasMission20000006(false); - // return; - // }; - - // setHasMission20000006(missionData && missionData.length > 0); - // } catch (error) { - // console.error("Error checking user mission: ", error); - // setHasMission20000006(false); - // }; - // }; - - // checkTutorialMission(); - // }, [session, supabase]); - useEffect(() => { 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; - }; - + .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`); + 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); - }; - }; - - if (session) { // && hasMission20000006) { - fetchAnomaly(); - }; - }, [session, hasMission20000006, supabase]); - + } + } + + fetchAnomaly(); + }, [session, supabase]); + if (loading) { return (
-

- Loading... -

+

Loading...

); - }; + } if (!anomaly) { return ( @@ -233,47 +228,36 @@ export function AiForMarsProject() {

No anomaly found.

); - }; + } const startTutorial = () => setShowTutorial(true); - const content = !hasMission20000006 - ? - : ( - <> - {loading &&

Loading...

} - {!loading && !anomaly &&

No anomaly found.

} - {!loading && anomaly && ( + return ( +
+ {!hasMission20000006 ? ( + + ) : ( <> -
- {imageUrl && Anomaly} -
{imageUrl && ( - + <> + + + )} - - )} - - + + )} +
); - -return ( -
- {content} -
-); - -}; - - // I did get conflicted between 3102 and 3103, going with 3102 until the satellite comes into play \ No newline at end of file +}; \ No newline at end of file