From 56be28c5dd0d59bbb33af2d59dc81cf5f0ba9346 Mon Sep 17 00:00:00 2001 From: Gizmotronn Date: Wed, 26 Feb 2025 21:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=8A=F0=9F=90=9E=20=E2=86=9D=20[SSC-86?= =?UTF-8?q?=20SSM-132=20SSM-115=20SSG-153]:=20New=20vote/surveyor=20interf?= =?UTF-8?q?aces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/planets/[id]/page.tsx | 30 ++-- .../PlanetHunters/PlanetGenerator.tsx | 4 +- .../Astronomers/PlanetHunters/PHVote.tsx | 114 ++++++++------- content/Classifications/UserLocations.tsx | 132 ++++++++++-------- 4 files changed, 159 insertions(+), 121 deletions(-) diff --git a/app/planets/[id]/page.tsx b/app/planets/[id]/page.tsx index 6b98954d..39c2db29 100644 --- a/app/planets/[id]/page.tsx +++ b/app/planets/[id]/page.tsx @@ -117,20 +117,22 @@ export default function ClassificationDetail({ params }: { params: { id: string /> )} {anomaly && classification.author === session?.user?.id && ( - +
+ +
)} {/* {anomaly && (
diff --git a/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator.tsx b/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator.tsx index cd0645c8..17642193 100644 --- a/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator.tsx +++ b/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator.tsx @@ -123,14 +123,14 @@ export default function PlanetGenerator({ classificationConfig, author, classifi onTypeOverride={handleTypeOverride} /> - {author === session?.user.id && ( + {/* {author === session?.user.id && ( - )} + )} */}
diff --git a/components/Structures/Missions/Astronomers/PlanetHunters/PHVote.tsx b/components/Structures/Missions/Astronomers/PlanetHunters/PHVote.tsx index 493f08a2..6ad3f079 100644 --- a/components/Structures/Missions/Astronomers/PlanetHunters/PHVote.tsx +++ b/components/Structures/Missions/Astronomers/PlanetHunters/PHVote.tsx @@ -16,13 +16,14 @@ interface Classification { classificationConfiguration: any | null; }; -export default function VotePlanetClassifictions() { +export default function VotePlanetClassifications() { const supabase = useSupabaseClient(); const session = useSession(); const [classifications, setClassifications] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [currentIndex, setCurrentIndex] = useState(0); const fetchClassifications = async () => { if (!session?.user) { @@ -30,38 +31,22 @@ export default function VotePlanetClassifictions() { setLoading(false); return; }; - + setLoading(true); setError(null); try { const { data, error } = await supabase .from('classifications') .select('*') - // .eq('author', session.user.id) .eq('classificationtype', 'planet') .order('created_at', { ascending: false }) as { data: Classification[]; error: any }; - + if (error) throw error; - - // const processedData = data.map((classification) => { - // const media = classification.media; - // let images: string[] = []; - - // if (Array.isArray(media) && media.length === 2 && typeof media[1] === "string") { - // images.push(media[1]); - // } else if (media && media.uploadUrl) { - // images.push(media.uploadUrl); - // } - - // const votes = classification.classificationConfiguration?.votes || 0; - - // return { ...classification, images, votes }; - // }); - + const processedData = data.map((classification) => { const media = classification.media; let image: string | null = null; - + if (Array.isArray(media)) { for (const subArray of media) { if (Array.isArray(subArray) && subArray.length > 0) { @@ -72,12 +57,12 @@ export default function VotePlanetClassifictions() { } else if (media && typeof media.uploadUrl === "string") { image = media.uploadUrl; } - + const votes = classification.classificationConfiguration?.votes || 0; - + return { ...classification, image, votes }; - }); - + }); + setClassifications(processedData); } catch (error) { console.error("Error fetching classifications:", error); @@ -85,26 +70,26 @@ export default function VotePlanetClassifictions() { } finally { setLoading(false); }; - }; + }; useEffect(() => { fetchClassifications(); - }, [session]) + }, [session]); const handleVote = async (classificationId: number, currentConfig: any) => { try { const currentVotes = currentConfig?.votes || 0; - + const updatedConfig = { ...currentConfig, votes: currentVotes + 1, }; - + const { error } = await supabase .from("classifications") .update({ classificationConfiguration: updatedConfig }) .eq("id", classificationId); - + if (error) { console.error("Error updating classificationConfiguration:", error); } else { @@ -121,32 +106,65 @@ export default function VotePlanetClassifictions() { } }; + const nextPost = () => { + setCurrentIndex((prevIndex) => Math.min(prevIndex + 1, classifications.length - 1)); + }; + + const prevPost = () => { + setCurrentIndex((prevIndex) => Math.max(prevIndex - 1, 0)); + }; + return ( -
+
+
{loading ? (

Loading classifications...

) : error ? (

{error}

) : ( - classifications.map((classification) => ( - ( +
handleVote(classification.id, classification.classificationConfiguration)} - /> + className={`flex-shrink-0 w-full max-w-screen-md ${index === currentIndex ? "block" : "hidden"}`} + > + handleVote(classification.id, classification.classificationConfiguration)} + /> +
)) )} -
+
+ +
+ +
+ +
+ +
+
); }; \ No newline at end of file diff --git a/content/Classifications/UserLocations.tsx b/content/Classifications/UserLocations.tsx index 9628b672..49e453d2 100644 --- a/content/Classifications/UserLocations.tsx +++ b/content/Classifications/UserLocations.tsx @@ -33,6 +33,7 @@ export default function MySettlementsLocations() { const [myLocations, setMyLocations] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [showAllUsers, setShowAllUsers] = useState(false); // State to toggle view async function fetchUserLocationClassifications() { if (!session) { @@ -42,12 +43,18 @@ export default function MySettlementsLocations() { }; try { - const { data: locationClassificationData, error: lcError } = await supabase + // Fetch classifications based on the toggle (whether to include all users or just the current user) + const query = supabase .from("classifications") .select("*, anomalies(content)") - .eq("author", session.user.id) .in("classificationtype", ["planet", "telescope-minorPlanet"]); + if (!showAllUsers) { + query.eq("author", session.user.id); // Only fetch the user's classifications + } + + const { data: locationClassificationData, error: lcError } = await query; + if (lcError) throw lcError; const enrichedClassifications = await Promise.all( @@ -95,7 +102,7 @@ export default function MySettlementsLocations() { useEffect(() => { fetchUserLocationClassifications(); - }, [session]); + }, [session, showAllUsers]); // Trigger fetch when `showAllUsers` changes if (loading) { return

Loading locations...

; @@ -113,61 +120,72 @@ export default function MySettlementsLocations() { const displayedAnomalies = new Set(); return ( -
- {myLocations - // Filter out classifications with no related classifications or with duplicate anomaly values - .filter(location => - location.relatedClassifications && - location.relatedClassifications.length > 0 && - !displayedAnomalies.has(location.anomaly) // Ensure anomaly is unique - ) - .map((location) => { - displayedAnomalies.add(location.anomaly); // Mark this anomaly as displayed - - return ( -
-

- {location.anomalyContent || `Location #${location.id}`} -

-

{location.content || ""}

- - {location.images && location.images.length > 0 && ( -
- {location.relatedClassifications && location.relatedClassifications.length > 0 && ( -
-

Related Classifications:

-
    - {location.relatedClassifications.map((related) => ( -
  • - {related.content || `Classification #${related.id}`} -
  • - ))} -
-
- )} - {location.images.map((image, index) => ( - {`Location - ))} -
- )} - - +
+ +
+ {myLocations + // Filter out classifications with no related classifications or with duplicate anomaly values + .filter(location => + location.relatedClassifications && + location.relatedClassifications.length > 0 && + !displayedAnomalies.has(location.anomaly) // Ensure anomaly is unique + ) + .map((location) => { + displayedAnomalies.add(location.anomaly); // Mark this anomaly as displayed + + return ( +
- View Classification - -
- ); - })} +

+ {location.anomalyContent || `Location #${location.id}`} +

+

{location.content || ""}

+ + {location.images && location.images.length > 0 && ( +
+ {location.relatedClassifications && location.relatedClassifications.length > 0 && ( +
+

Related Classifications:

+
    + {location.relatedClassifications.map((related) => ( +
  • + {related.content || `Classification #${related.id}`} +
  • + ))} +
+
+ )} + {location.images.map((image, index) => ( + {`Location + ))} +
+ )} + + +
+ ); + })} +
); }; \ No newline at end of file