From a162bd05d3a7f826bc33dcdef8ba737176a471a0 Mon Sep 17 00:00:00 2001 From: Gizmotronn Date: Thu, 14 Nov 2024 15:02:30 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=91=F0=9F=95=BA=F0=9F=8F=BE=20?= =?UTF-8?q?=E2=86=9D=20[SSM-21=20SSM-61=20SSM-41]:=20Combining=20classific?= =?UTF-8?q?ations=20&=20post/anomaly=20cards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tests/page.tsx | 5 +- .../(classifications)/Collections/All.tsx | 8 +-- .../Collections/ByActivePlanet.tsx | 2 +- .../Collections/ByClassType.tsx | 15 ++-- .../Collections/Classification.tsx | 42 +++++++---- content/Starnet/YourClassifications.tsx | 70 ++++++++++++++----- 6 files changed, 97 insertions(+), 45 deletions(-) diff --git a/app/tests/page.tsx b/app/tests/page.tsx index 13e04571..80c3044b 100644 --- a/app/tests/page.tsx +++ b/app/tests/page.tsx @@ -7,11 +7,14 @@ import InventoryPage from "@/components/Inventory/Grid/Grid"; import TelescopeComponent from "@/constants/Structures/Telescope"; import ZoodexComponent from "@/constants/Structures/Zoodex"; import { CreateStructure } from "@/components/Structures/Build/CreateDedicatedStructure"; +import AllClassifications from "@/content/Starnet/YourClassifications"; export default function TestPage() { return ( - <> + <> + + ); }; diff --git a/components/Projects/(classifications)/Collections/All.tsx b/components/Projects/(classifications)/Collections/All.tsx index a08ed904..83777a98 100644 --- a/components/Projects/(classifications)/Collections/All.tsx +++ b/components/Projects/(classifications)/Collections/All.tsx @@ -15,10 +15,10 @@ export function DiscoveryCards() { useEffect(() => { const fetchClassifications = async () => { if (!session?.user) { - setError('User session not found.'); + setError('User session not found.'); setLoading(false); return; - } + }; setLoading(true); setError(null); @@ -36,7 +36,7 @@ export function DiscoveryCards() { setError('Failed to load classifications.'); } finally { setLoading(false); - } + }; }; fetchClassifications(); @@ -53,4 +53,4 @@ export function DiscoveryCards() { ))} ); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/components/Projects/(classifications)/Collections/ByActivePlanet.tsx b/components/Projects/(classifications)/Collections/ByActivePlanet.tsx index dfa34245..ff3832f0 100644 --- a/components/Projects/(classifications)/Collections/ByActivePlanet.tsx +++ b/components/Projects/(classifications)/Collections/ByActivePlanet.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useSupabaseClient } from '@supabase/auth-helpers-react'; import { DiscoveryCardSingle } from './Classification'; diff --git a/components/Projects/(classifications)/Collections/ByClassType.tsx b/components/Projects/(classifications)/Collections/ByClassType.tsx index 83e94a44..dbf59089 100644 --- a/components/Projects/(classifications)/Collections/ByClassType.tsx +++ b/components/Projects/(classifications)/Collections/ByClassType.tsx @@ -4,13 +4,13 @@ import React, { useEffect, useState } from 'react'; import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react'; import { DiscoveryCardSingle } from './Classification'; -interface DiscoveryCardsByClassificationTypeProps { +interface DiscoveryCardsByClassificationTypeProps { classificationtype: string; }; export function DiscoveryCardsByClassificationType({ classificationtype }: DiscoveryCardsByClassificationTypeProps) { const supabase = useSupabaseClient(); -const session = useSession(); + const session = useSession(); const [classifications, setClassifications] = useState([]); const [loading, setLoading] = useState(true); @@ -23,9 +23,8 @@ const session = useSession(); try { const { data, error } = await supabase .from('classifications') - .select('id') - .eq('author', session?.user.id) - .eq('anomaly', classificationtype); + .select('*') + .eq('classificationtype', classificationtype); if (error) throw error; @@ -38,12 +37,14 @@ const session = useSession(); } }; - fetchClassifications(); + if (classificationtype) { + fetchClassifications(); + } }, [classificationtype, supabase]); if (loading) return

Loading...

; if (error) return

{error}

; - if (classifications.length === 0) return

No classifications found for this anomaly by user

; + if (classifications.length === 0) return

No classifications found for this classification type

; return (
diff --git a/components/Projects/(classifications)/Collections/Classification.tsx b/components/Projects/(classifications)/Collections/Classification.tsx index ad4417fe..56ad2863 100644 --- a/components/Projects/(classifications)/Collections/Classification.tsx +++ b/components/Projects/(classifications)/Collections/Classification.tsx @@ -44,10 +44,6 @@ const generateImagePlaceholder = (name: string) => { return canvas.toDataURL(); }; -interface DiscoveryCardSingleProps { - classificationId: number; -}; - const extractImageUrls = (media: any): string[] => { let imageUrls: string[] = []; @@ -75,21 +71,33 @@ const extractImageUrls = (media: any): string[] => { export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSingleProps) { const supabase = useSupabaseClient(); const [classification, setClassification] = useState(null); + const [anomaly, setAnomaly] = useState(null); // For anomaly data const [loading, setLoading] = useState(true); useEffect(() => { const fetchClassification = async () => { setLoading(true); try { + // Fetch classification data along with anomaly data (join anomalies table) const { data, error } = await supabase .from('classifications') - .select('id, content, classificationtype, created_at, media, anomaly, classificationConfiguration') + .select('id, content, classificationtype, created_at, media, anomaly, classificationConfiguration, anomalies(avatar_url)') .eq('id', classificationId) .single(); if (error) throw error; setClassification(data); + if (data.anomaly) { + // Fetch anomaly data separately if needed + const { data: anomalyData } = await supabase + .from('anomalies') + .select('avatar_url') + .eq('id', data.anomaly) + .single(); + + setAnomaly(anomalyData); // Store the anomaly's avatar_url + } } catch (error) { console.error('Error fetching classification:', error); } finally { @@ -103,9 +111,9 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro if (loading) return

Loading...

; if (!classification) return

No classification found.

; - const { content, classificationtype, created_at, media, anomaly, classificationConfiguration } = classification; + const { content, classificationtype, created_at, media, classificationConfiguration } = classification; const discoveredOn = new Date(created_at).toLocaleDateString(); - const parentAnomaly = anomaly ? `Anomaly ID: ${anomaly}` : 'Earth'; + const parentAnomaly = classification.anomaly ? `Anomaly ID: ${classification.anomaly}` : 'Earth'; // Extract URLs from the media column const imageUrls = extractImageUrls(media); @@ -137,6 +145,19 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro Parent Anomaly: {parentAnomaly}
+ + {/* Display Anomaly Avatar if available */} + {anomaly?.avatar_url && ( +
+

Anomaly Avatar:

+ Anomaly Avatar +
+ )} +

Classification Configuration:

{JSON.stringify(classificationConfiguration, null, 2)}
@@ -158,9 +179,4 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro ); -}; - - -interface ClassificationConfiguration { - [key: string]: string | number | boolean; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/content/Starnet/YourClassifications.tsx b/content/Starnet/YourClassifications.tsx index 6ad785c5..7691e729 100644 --- a/content/Starnet/YourClassifications.tsx +++ b/content/Starnet/YourClassifications.tsx @@ -1,11 +1,15 @@ -"use client"; +'use client'; -import React, { useState } from "react"; -import { DiscoveryCards } from "@/components/Projects/(classifications)/Collections/All"; -import { DiscoveryCardsByActivePlanet } from "@/components/Projects/(classifications)/Collections/ByActivePlanet"; -import { DiscoveryCardsByUserAndAnomaly } from "@/components/Projects/(classifications)/Collections/ByAnomaly"; +import React, { useState, useEffect } from 'react'; +import { useSupabaseClient } from '@supabase/auth-helpers-react'; +import { DiscoveryCardsByClassificationType } from '@/components/Projects/(classifications)/Collections/ByClassType'; +import { DiscoveryCardsByUserAndAnomaly } from '@/components/Projects/(classifications)/Collections/ByAnomaly'; export default function AllClassifications() { + const supabase = useSupabaseClient(); + const [classificationTypes, setClassificationTypes] = useState([]); + const [selectedType, setSelectedType] = useState(''); + const [activePlanet, setActivePlanet] = useState(null); const [anomalyId, setAnomalyId] = useState(null); @@ -17,27 +21,55 @@ export default function AllClassifications() { setAnomalyId(Number(e.target.value)); }; + useEffect(() => { + const fetchClassificationTypes = async () => { + try { + const { data, error } = await supabase + .from('classifications') + .select('classificationtype') // Select classificationtype column + .neq('classificationtype', null); // Exclude null values + + if (error) throw error; + + // Remove duplicates manually by using Set + const uniqueTypes = Array.from(new Set(data.map((row: { classificationtype: string }) => row.classificationtype))); + setClassificationTypes(uniqueTypes); + } catch (error) { + console.error('Error fetching classification types:', error); + } + }; + + fetchClassificationTypes(); + }, [supabase]); + + const handleTypeChange = (e: React.ChangeEvent) => { + setSelectedType(e.target.value); + }; + return (
- -
-

Select Active Planet

+

Select Classification Type

- + > + + {classificationTypes.map((type, idx) => ( + + ))} +
- {activePlanet !== null && ( - + {selectedType && ( + )}
-
+ {/*

Select Anomaly

)} -
+
*/}
); -} \ No newline at end of file +}; \ No newline at end of file