1
1
import React , { useEffect , useState } from "react" ;
2
2
import { useSession , useSupabaseClient , SupabaseClient } from "@supabase/auth-helpers-react" ;
3
- import CardForum , { CommentItem , RoverContentCard } from "./DiscussCard" ;
3
+ import CardForum from "./DiscussCard" ;
4
4
5
5
export function ClassificationFeedForIndividualPlanet ( planetId , backgroundColorSet ) {
6
6
const supabase : SupabaseClient = useSupabaseClient ( ) ;
@@ -13,12 +13,6 @@ export function ClassificationFeedForIndividualPlanet(planetId, backgroundColorS
13
13
useEffect ( ( ) => {
14
14
fetchPosts ( ) ;
15
15
} , [ ] ) ;
16
-
17
- useEffect ( ( ) => {
18
- if ( planetPosts . length > 0 ) {
19
- console . log ( "Comments: " , planetPosts . flatMap ( ( post ) => post . comments ) ) ;
20
- }
21
- } , [ ] ) ;
22
16
23
17
async function fetchPosts ( ) {
24
18
try {
@@ -73,78 +67,4 @@ export function ClassificationFeedForIndividualPlanet(planetId, backgroundColorS
73
67
) ) }
74
68
</ div >
75
69
) ;
76
- } ;
77
-
78
- export function ClassificationFeedForIndividualPlanetDuplicates ( planetId ) {
79
- const supabase : SupabaseClient = useSupabaseClient ( ) ;
80
- const session = useSession ( ) ;
81
-
82
- const [ posts , setPosts ] = useState ( [ ] ) ;
83
- // const [profile, setProfile] = useState(null);
84
- const [ planetPosts , setPlanetPosts ] = useState ( [ ] ) ;
85
-
86
- useEffect ( ( ) => {
87
- fetchPosts ( ) ;
88
- } , [ ] ) ;
89
-
90
- useEffect ( ( ) => {
91
- if ( planetPosts . length > 0 ) {
92
- console . log ( "Comments: " , planetPosts . flatMap ( ( post ) => post . comments ) ) ;
93
- }
94
- } , [ ] ) ;
95
-
96
- async function fetchPosts ( ) {
97
- try {
98
- const postsResponse = await supabase
99
- . from ( "posts_duplicates" )
100
- . select (
101
- "id, anomaly, content, created_at, planets2, planetsss(id, temperature), profiles(id, avatar_url, full_name, username)"
102
- )
103
- // .eq('anomaly', planetId) // 'planets2', planetId
104
- . order ( 'created_at' , { ascending : false } ) ;
105
-
106
- if ( postsResponse . error || ! postsResponse . data ) {
107
- console . error ( "Error fetching posts:" , postsResponse . error ) ;
108
- return ;
109
- }
110
-
111
- const postIds = postsResponse . data . map ( ( post ) => post . id ) ;
112
-
113
- const commentsResponse = await supabase
114
- . from ( "comments" )
115
- . select ( "id, content, created_at, profiles(id, avatar_url, username), post_id" )
116
- . in ( "post_id" , postIds )
117
- . order ( "created_at" , { ascending : true } ) ;
118
-
119
- const commentsByPostId = commentsResponse . data . reduce ( ( acc , comment ) => {
120
- const postId = comment . post_id ;
121
- if ( ! acc [ postId ] ) {
122
- acc [ postId ] = [ ] ;
123
- }
124
- acc [ postId ] . push ( comment ) ;
125
- return acc ;
126
- } , { } ) ;
127
-
128
- const postsWithComments = postsResponse . data . map ( ( post ) => ( {
129
- ...post ,
130
- comments : commentsByPostId [ post . id ] || [ ] ,
131
- } ) ) ;
132
-
133
- setPosts ( postsWithComments ) ;
134
- console . log ( posts ) ;
135
- } catch ( error ) {
136
- console . error ( "Error fetching posts:" , error . message ) ;
137
- }
138
- }
139
-
140
- return (
141
- < div className = "flex flex-col items-center gap-4 py-2" style = { { maxWidth : '100%' , margin : 'auto' } } >
142
- { posts . map ( ( post ) => (
143
- < >
144
- < CardForum key = { post . id } { ...post } />
145
- < p > { post . planetId } </ p >
146
- </ >
147
- ) ) }
148
- </ div >
149
- ) ;
150
70
} ;
0 commit comments