Skip to content

Commit a162bd0

Browse files
committed
🦑🕺🏾 ↝ [SSM-21 SSM-61 SSM-41]: Combining classifications & post/anomaly cards
1 parent 349b5b7 commit a162bd0

File tree

6 files changed

+97
-45
lines changed

6 files changed

+97
-45
lines changed

app/tests/page.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import InventoryPage from "@/components/Inventory/Grid/Grid";
77
import TelescopeComponent from "@/constants/Structures/Telescope";
88
import ZoodexComponent from "@/constants/Structures/Zoodex";
99
import { CreateStructure } from "@/components/Structures/Build/CreateDedicatedStructure";
10+
import AllClassifications from "@/content/Starnet/YourClassifications";
1011

1112
export default function TestPage() {
1213
return (
1314
<StarnetLayout>
14-
<></>
15+
<>
16+
<AllClassifications />
17+
</>
1518
</StarnetLayout>
1619
);
1720
};

components/Projects/(classifications)/Collections/All.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function DiscoveryCards() {
1515
useEffect(() => {
1616
const fetchClassifications = async () => {
1717
if (!session?.user) {
18-
setError('User session not found.');
18+
setError('User session not found.');
1919
setLoading(false);
2020
return;
21-
}
21+
};
2222

2323
setLoading(true);
2424
setError(null);
@@ -36,7 +36,7 @@ export function DiscoveryCards() {
3636
setError('Failed to load classifications.');
3737
} finally {
3838
setLoading(false);
39-
}
39+
};
4040
};
4141

4242
fetchClassifications();
@@ -53,4 +53,4 @@ export function DiscoveryCards() {
5353
))}
5454
</div>
5555
);
56-
}
56+
};

components/Projects/(classifications)/Collections/ByActivePlanet.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useEffect, useState } from 'react';
3+
import React, { useEffect, useState } from 'react';
44
import { useSupabaseClient } from '@supabase/auth-helpers-react';
55
import { DiscoveryCardSingle } from './Classification';
66

components/Projects/(classifications)/Collections/ByClassType.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import React, { useEffect, useState } from 'react';
44
import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react';
55
import { DiscoveryCardSingle } from './Classification';
66

7-
interface DiscoveryCardsByClassificationTypeProps {
7+
interface DiscoveryCardsByClassificationTypeProps {
88
classificationtype: string;
99
};
1010

1111
export function DiscoveryCardsByClassificationType({ classificationtype }: DiscoveryCardsByClassificationTypeProps) {
1212
const supabase = useSupabaseClient();
13-
const session = useSession();
13+
const session = useSession();
1414

1515
const [classifications, setClassifications] = useState<any[]>([]);
1616
const [loading, setLoading] = useState<boolean>(true);
@@ -23,9 +23,8 @@ const session = useSession();
2323
try {
2424
const { data, error } = await supabase
2525
.from('classifications')
26-
.select('id')
27-
.eq('author', session?.user.id)
28-
.eq('anomaly', classificationtype);
26+
.select('*')
27+
.eq('classificationtype', classificationtype);
2928

3029
if (error) throw error;
3130

@@ -38,12 +37,14 @@ const session = useSession();
3837
}
3938
};
4039

41-
fetchClassifications();
40+
if (classificationtype) {
41+
fetchClassifications();
42+
}
4243
}, [classificationtype, supabase]);
4344

4445
if (loading) return <p>Loading...</p>;
4546
if (error) return <p>{error}</p>;
46-
if (classifications.length === 0) return <p>No classifications found for this anomaly by user</p>;
47+
if (classifications.length === 0) return <p>No classifications found for this classification type</p>;
4748

4849
return (
4950
<div className="flex flex-col space-y-4">

components/Projects/(classifications)/Collections/Classification.tsx

+29-13
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ const generateImagePlaceholder = (name: string) => {
4444
return canvas.toDataURL();
4545
};
4646

47-
interface DiscoveryCardSingleProps {
48-
classificationId: number;
49-
};
50-
5147
const extractImageUrls = (media: any): string[] => {
5248
let imageUrls: string[] = [];
5349

@@ -75,21 +71,33 @@ const extractImageUrls = (media: any): string[] => {
7571
export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSingleProps) {
7672
const supabase = useSupabaseClient();
7773
const [classification, setClassification] = useState<any>(null);
74+
const [anomaly, setAnomaly] = useState<any>(null); // For anomaly data
7875
const [loading, setLoading] = useState<boolean>(true);
7976

8077
useEffect(() => {
8178
const fetchClassification = async () => {
8279
setLoading(true);
8380
try {
81+
// Fetch classification data along with anomaly data (join anomalies table)
8482
const { data, error } = await supabase
8583
.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)')
8785
.eq('id', classificationId)
8886
.single();
8987

9088
if (error) throw error;
9189

9290
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+
}
93101
} catch (error) {
94102
console.error('Error fetching classification:', error);
95103
} finally {
@@ -103,9 +111,9 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
103111
if (loading) return <p>Loading...</p>;
104112
if (!classification) return <p>No classification found.</p>;
105113

106-
const { content, classificationtype, created_at, media, anomaly, classificationConfiguration } = classification;
114+
const { content, classificationtype, created_at, media, classificationConfiguration } = classification;
107115
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';
109117

110118
// Extract URLs from the media column
111119
const imageUrls = extractImageUrls(media);
@@ -137,6 +145,19 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
137145
<Globe className="w-4 h-4 text-slate-600" />
138146
<span className="text-sm">Parent Anomaly: {parentAnomaly}</span>
139147
</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+
140161
<div className="mt-4">
141162
<h3 className="font-semibold">Classification Configuration:</h3>
142163
<pre>{JSON.stringify(classificationConfiguration, null, 2)}</pre>
@@ -158,9 +179,4 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
158179
</CardContent>
159180
</Card>
160181
);
161-
};
162-
163-
164-
interface ClassificationConfiguration {
165-
[key: string]: string | number | boolean;
166-
}
182+
};
+51-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
"use client";
1+
'use client';
22

3-
import React, { useState } from "react";
4-
import { DiscoveryCards } from "@/components/Projects/(classifications)/Collections/All";
5-
import { DiscoveryCardsByActivePlanet } from "@/components/Projects/(classifications)/Collections/ByActivePlanet";
6-
import { DiscoveryCardsByUserAndAnomaly } from "@/components/Projects/(classifications)/Collections/ByAnomaly";
3+
import React, { useState, useEffect } from 'react';
4+
import { useSupabaseClient } from '@supabase/auth-helpers-react';
5+
import { DiscoveryCardsByClassificationType } from '@/components/Projects/(classifications)/Collections/ByClassType';
6+
import { DiscoveryCardsByUserAndAnomaly } from '@/components/Projects/(classifications)/Collections/ByAnomaly';
77

88
export default function AllClassifications() {
9+
const supabase = useSupabaseClient();
10+
const [classificationTypes, setClassificationTypes] = useState<string[]>([]);
11+
const [selectedType, setSelectedType] = useState<string>('');
12+
913
const [activePlanet, setActivePlanet] = useState<number | null>(null);
1014
const [anomalyId, setAnomalyId] = useState<number | null>(null);
1115

@@ -17,27 +21,55 @@ export default function AllClassifications() {
1721
setAnomalyId(Number(e.target.value));
1822
};
1923

24+
useEffect(() => {
25+
const fetchClassificationTypes = async () => {
26+
try {
27+
const { data, error } = await supabase
28+
.from('classifications')
29+
.select('classificationtype') // Select classificationtype column
30+
.neq('classificationtype', null); // Exclude null values
31+
32+
if (error) throw error;
33+
34+
// Remove duplicates manually by using Set
35+
const uniqueTypes = Array.from(new Set(data.map((row: { classificationtype: string }) => row.classificationtype)));
36+
setClassificationTypes(uniqueTypes);
37+
} catch (error) {
38+
console.error('Error fetching classification types:', error);
39+
}
40+
};
41+
42+
fetchClassificationTypes();
43+
}, [supabase]);
44+
45+
const handleTypeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
46+
setSelectedType(e.target.value);
47+
};
48+
2049
return (
2150
<div className="py-2 space-y-8">
22-
<DiscoveryCards />
23-
2451
<div>
25-
<h3>Select Active Planet</h3>
52+
<h3>Select Classification Type</h3>
2653
<form className="space-y-4">
27-
<input
28-
type="number"
29-
placeholder="Enter Active Planet ID"
30-
value={activePlanet || ""}
31-
onChange={handleActivePlanetChange}
54+
<select
55+
value={selectedType}
56+
onChange={handleTypeChange}
3257
className="border rounded p-2"
33-
/>
58+
>
59+
<option value="">Select Classification Type</option>
60+
{classificationTypes.map((type, idx) => (
61+
<option key={idx} value={type}>
62+
{type}
63+
</option>
64+
))}
65+
</select>
3466
</form>
35-
{activePlanet !== null && (
36-
<DiscoveryCardsByActivePlanet activePlanet={activePlanet} />
67+
{selectedType && (
68+
<DiscoveryCardsByClassificationType classificationtype={selectedType} />
3769
)}
3870
</div>
3971

40-
<div>
72+
{/* <div>
4173
<h3>Select Anomaly</h3>
4274
<form className="space-y-4">
4375
<input
@@ -51,7 +83,7 @@ export default function AllClassifications() {
5183
{anomalyId !== null && (
5284
<DiscoveryCardsByUserAndAnomaly anomalyId={anomalyId} />
5385
)}
54-
</div>
86+
</div> */}
5587
</div>
5688
);
57-
}
89+
};

0 commit comments

Comments
 (0)