@@ -44,10 +44,6 @@ const generateImagePlaceholder = (name: string) => {
44
44
return canvas . toDataURL ( ) ;
45
45
} ;
46
46
47
- interface DiscoveryCardSingleProps {
48
- classificationId : number ;
49
- } ;
50
-
51
47
const extractImageUrls = ( media : any ) : string [ ] => {
52
48
let imageUrls : string [ ] = [ ] ;
53
49
@@ -75,21 +71,33 @@ const extractImageUrls = (media: any): string[] => {
75
71
export function DiscoveryCardSingle ( { classificationId } : DiscoveryCardSingleProps ) {
76
72
const supabase = useSupabaseClient ( ) ;
77
73
const [ classification , setClassification ] = useState < any > ( null ) ;
74
+ const [ anomaly , setAnomaly ] = useState < any > ( null ) ; // For anomaly data
78
75
const [ loading , setLoading ] = useState < boolean > ( true ) ;
79
76
80
77
useEffect ( ( ) => {
81
78
const fetchClassification = async ( ) => {
82
79
setLoading ( true ) ;
83
80
try {
81
+ // Fetch classification data along with anomaly data (join anomalies table)
84
82
const { data, error } = await supabase
85
83
. from ( 'classifications' )
86
- . select ( 'id, content, classificationtype, created_at, media, anomaly, classificationConfiguration' )
84
+ . select ( 'id, content, classificationtype, created_at, media, anomaly, classificationConfiguration, anomalies(avatar_url) ' )
87
85
. eq ( 'id' , classificationId )
88
86
. single ( ) ;
89
87
90
88
if ( error ) throw error ;
91
89
92
90
setClassification ( data ) ;
91
+ if ( data . anomaly ) {
92
+ // Fetch anomaly data separately if needed
93
+ const { data : anomalyData } = await supabase
94
+ . from ( 'anomalies' )
95
+ . select ( 'avatar_url' )
96
+ . eq ( 'id' , data . anomaly )
97
+ . single ( ) ;
98
+
99
+ setAnomaly ( anomalyData ) ; // Store the anomaly's avatar_url
100
+ }
93
101
} catch ( error ) {
94
102
console . error ( 'Error fetching classification:' , error ) ;
95
103
} finally {
@@ -103,9 +111,9 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
103
111
if ( loading ) return < p > Loading...</ p > ;
104
112
if ( ! classification ) return < p > No classification found.</ p > ;
105
113
106
- const { content, classificationtype, created_at, media, anomaly , classificationConfiguration } = classification ;
114
+ const { content, classificationtype, created_at, media, classificationConfiguration } = classification ;
107
115
const discoveredOn = new Date ( created_at ) . toLocaleDateString ( ) ;
108
- const parentAnomaly = anomaly ? `Anomaly ID: ${ anomaly } ` : 'Earth' ;
116
+ const parentAnomaly = classification . anomaly ? `Anomaly ID: ${ classification . anomaly } ` : 'Earth' ;
109
117
110
118
// Extract URLs from the media column
111
119
const imageUrls = extractImageUrls ( media ) ;
@@ -137,6 +145,19 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
137
145
< Globe className = "w-4 h-4 text-slate-600" />
138
146
< span className = "text-sm" > Parent Anomaly: { parentAnomaly } </ span >
139
147
</ div >
148
+
149
+ { /* Display Anomaly Avatar if available */ }
150
+ { anomaly ?. avatar_url && (
151
+ < div className = "mt-4" >
152
+ < h3 className = "font-semibold" > Anomaly Avatar:</ h3 >
153
+ < img
154
+ src = { anomaly . avatar_url }
155
+ alt = "Anomaly Avatar"
156
+ className = "w-16 h-16 rounded-full object-cover shadow-md"
157
+ />
158
+ </ div >
159
+ ) }
160
+
140
161
< div className = "mt-4" >
141
162
< h3 className = "font-semibold" > Classification Configuration:</ h3 >
142
163
< pre > { JSON . stringify ( classificationConfiguration , null , 2 ) } </ pre >
@@ -158,9 +179,4 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
158
179
</ CardContent >
159
180
</ Card >
160
181
) ;
161
- } ;
162
-
163
-
164
- interface ClassificationConfiguration {
165
- [ key : string ] : string | number | boolean ;
166
- }
182
+ } ;
0 commit comments