From 14a56fa7d4e332add582d4b2e65d62b21f582d65 Mon Sep 17 00:00:00 2001 From: Gizmotronn Date: Wed, 16 Oct 2024 00:04:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=93=F0=9F=A7=A4=20=E2=86=9D=20[SSP-9?= =?UTF-8?q?=20SSP-29=20SSP-30]:=20Working=20multiple=20content/files=20for?= =?UTF-8?q?=20DMP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- citizen | 2 +- .../Projects/(classifications)/PostForm.tsx | 42 +++++----- .../Projects/Telescopes/DailyMinorPlanet.tsx | 78 ++++++++++++------- 3 files changed, 72 insertions(+), 50 deletions(-) diff --git a/citizen b/citizen index da5468f9..68080cc8 160000 --- a/citizen +++ b/citizen @@ -1 +1 @@ -Subproject commit da5468f9801d5f8deb0e21897bb7f010adb6f974 +Subproject commit 68080cc89af4f173732e0cb40f99c9d2cfcc4feb diff --git a/components/Projects/(classifications)/PostForm.tsx b/components/Projects/(classifications)/PostForm.tsx index 40b326ad..1b1cbbb8 100644 --- a/components/Projects/(classifications)/PostForm.tsx +++ b/components/Projects/(classifications)/PostForm.tsx @@ -128,27 +128,27 @@ const ClassificationForm: React.FC = ({ const [hasClassified, setHasClassified] = useState(false); - useEffect(() => { - const checkUserClassification = async () => { - if (!session?.user?.id || !anomalyId) return; - - const { data, error } = await supabase - .from("classifications") - .select("id") - .eq("author", session.user.id) - .eq("anomaly", anomalyId) - .single(); - - if (data) { - setHasClassified(true); - } - if (error) { - console.error("Error checking classification:", error.message); - } - }; - - checkUserClassification(); - }, [session?.user?.id, anomalyId, supabase]); +// useEffect(() => { +// const checkUserClassification = async () => { +// if (!session?.user?.id || !anomalyId) return; + +// const { data, error } = await supabase +// .from("classifications") +// .select("id") +// .eq("author", session.user.id) +// .eq("anomaly", anomalyId) +// .single(); + +// if (data) { +// setHasClassified(true); +// } +// if (error) { +// console.error("Error checking classification:", error.message); +// } +// }; + +// checkUserClassification(); +// }, [session?.user?.id, anomalyId, supabase]); useEffect(() => { const fetchUserProfile = async () => { diff --git a/components/Projects/Telescopes/DailyMinorPlanet.tsx b/components/Projects/Telescopes/DailyMinorPlanet.tsx index 6205f755..5a8ee81d 100644 --- a/components/Projects/Telescopes/DailyMinorPlanet.tsx +++ b/components/Projects/Telescopes/DailyMinorPlanet.tsx @@ -131,11 +131,11 @@ export function DailyMinorPlanet() { const session = useSession(); const [anomaly, setAnomaly] = useState(null); - const [imageUrl, setImageUrl] = useState(null); + const [imageUrls, setImageUrls] = useState([]); + const [currentImageIndex, setCurrentImageIndex] = useState(0); const [loading, setLoading] = useState(true); const [missionLoading, setMissionLoading] = useState(true); - const [hasMission20000003, setHasMission20000003] = useState(false); useEffect(() => { @@ -144,7 +144,7 @@ export function DailyMinorPlanet() { setLoading(false); return; } - + try { const { data: missionData, error: missionError } = await supabase .from("missions") @@ -152,26 +152,23 @@ export function DailyMinorPlanet() { .eq("user", session.user.id) .eq("mission", 20000003) .single(); - - console.log("Mission Data:", missionData); - + if (missionError) { throw missionError; } - + setHasMission20000003(!!missionData); } catch (error: any) { console.error("Mission error:", error); setHasMission20000003(false); } finally { setMissionLoading(false); - } + }; }; - + checkTutorialMission(); }, [session, supabase]); - // Fetch anomaly data useEffect(() => { if (!hasMission20000003 || missionLoading || !session) return; @@ -181,14 +178,22 @@ export function DailyMinorPlanet() { .from("anomalies") .select("*") .eq("anomalySet", "telescope-minorPlanet"); - + if (anomalyError) { throw anomalyError; } - + const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly; setAnomaly(randomAnomaly); - setImageUrl(`${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}.png`); + + // Set URLs for carousel images + const imageUrls = [ + `${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/1.png`, + `${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/2.png`, + `${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/3.png`, + `${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/4.png` + ]; + setImageUrls(imageUrls); } catch (error: any) { console.error("Error fetching anomaly", error.message); setAnomaly(null); @@ -200,42 +205,59 @@ export function DailyMinorPlanet() { fetchAnomaly(); }, [hasMission20000003, missionLoading, session, supabase]); - // Handle loading states + const handlePrevious = () => { + setCurrentImageIndex((prevIndex) => (prevIndex === 0 ? imageUrls.length - 1 : prevIndex - 1)); + }; + + const handleNext = () => { + setCurrentImageIndex((prevIndex) => (prevIndex === imageUrls.length - 1 ? 0 : prevIndex + 1)); + }; + if (loading || missionLoading) { return
Loading...
; } - // Render conditionally based on mission if (!hasMission20000003) { - return ; - } + return ; + }; - // Render anomaly or no anomaly found message if (!anomaly) { return (

No anomaly found.

); - } + }; return (
- {imageUrl && ( - Anomaly + {imageUrls.length > 0 && ( +
+ {`Anomaly + + +
+ {imageUrls.map((_, index) => ( + + ))} +
+
)}
- {imageUrl && ( + {imageUrls.length > 0 && ( )}