Skip to content

Commit

Permalink
🐳🍨 ↝ Removing most mention of comment components for now [ SGV2-8 // …
Browse files Browse the repository at this point in the history
…FCDB-6 ]
  • Loading branch information
Gizmotronn committed Mar 18, 2024
1 parent d606fc5 commit edb7e68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 124 deletions.
82 changes: 1 addition & 81 deletions components/Content/ClassificationFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { useSession, useSupabaseClient, SupabaseClient } from "@supabase/auth-helpers-react";
import CardForum, { CommentItem, RoverContentCard } from "./DiscussCard";
import CardForum from "./DiscussCard";

export function ClassificationFeedForIndividualPlanet(planetId, backgroundColorSet) {
const supabase: SupabaseClient = useSupabaseClient();
Expand All @@ -13,12 +13,6 @@ export function ClassificationFeedForIndividualPlanet(planetId, backgroundColorS
useEffect(() => {
fetchPosts();
}, []);

useEffect(() => {
if (planetPosts.length > 0) {
console.log("Comments: ", planetPosts.flatMap((post) => post.comments));
}
}, []);

async function fetchPosts() {
try {
Expand Down Expand Up @@ -73,78 +67,4 @@ export function ClassificationFeedForIndividualPlanet(planetId, backgroundColorS
))}
</div>
);
};

export function ClassificationFeedForIndividualPlanetDuplicates(planetId) {
const supabase: SupabaseClient = useSupabaseClient();
const session = useSession();

const [posts, setPosts] = useState([]);
// const [profile, setProfile] = useState(null);
const [planetPosts, setPlanetPosts] = useState([]);

useEffect(() => {
fetchPosts();
}, []);

useEffect(() => {
if (planetPosts.length > 0) {
console.log("Comments: ", planetPosts.flatMap((post) => post.comments));
}
}, []);

async function fetchPosts() {
try {
const postsResponse = await supabase
.from("posts_duplicates")
.select(
"id, anomaly, content, created_at, planets2, planetsss(id, temperature), profiles(id, avatar_url, full_name, username)"
)
// .eq('anomaly', planetId) // 'planets2', planetId
.order('created_at', { ascending: false });

if (postsResponse.error || !postsResponse.data) {
console.error("Error fetching posts:", postsResponse.error);
return;
}

const postIds = postsResponse.data.map((post) => post.id);

const commentsResponse = await supabase
.from("comments")
.select("id, content, created_at, profiles(id, avatar_url, username), post_id")
.in("post_id", postIds)
.order("created_at", { ascending: true });

const commentsByPostId = commentsResponse.data.reduce((acc, comment) => {
const postId = comment.post_id;
if (!acc[postId]) {
acc[postId] = [];
}
acc[postId].push(comment);
return acc;
}, {});

const postsWithComments = postsResponse.data.map((post) => ({
...post,
comments: commentsByPostId[post.id] || [],
}));

setPosts(postsWithComments);
console.log(posts);
} catch (error) {
console.error("Error fetching posts:", error.message);
}
}

return (
<div className="flex flex-col items-center gap-4 py-2" style={{ maxWidth: '100%', margin: 'auto' }}>
{posts.map((post) => (
<>
<CardForum key={post.id} {...post} />
<p>{post.planetId}</p>
</>
))}
</div>
);
};
44 changes: 1 addition & 43 deletions components/Content/DiscussCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,6 @@ interface Comment {
avatar_url: string;
username: string;
};
}

export const CommentItem: React.FC<Comment> = ({ id, content, created_at, profiles }) => {
return (
<div className="ml-2 my-3">
<div className="flex items-center mb-2">
<Avatar className="rounded-full">
<AvatarImage src={"https://qwbufbmxkjfaikoloudl.supabase.co/storage/v1/object/public/avatars/" + profiles?.avatar_url ?? ""} />
<AvatarFallback>Test</AvatarFallback>
</Avatar>
<div className="flex flex-wrap items-center ml-2">
<div className="font-bold">{profiles?.username}</div>
</div>
</div>
<div className="my-3 text-sm">{content}</div>
</div>
);
};

const CardForum: React.FC<TProps> = ({
Expand Down Expand Up @@ -107,31 +90,6 @@ const CardForum: React.FC<TProps> = ({
</CardContent>
<CardFooter className="p-0 flex-col items-start pb-2">
<Separator className="mb-2" />
{/* <div className="space-x-2 px-4 py-2">
{comments && (
<Button onClick={toggleComments} variant="outline" size="default" className="space-x-2">
<MessagesSquare className="w-5 aspect-square" />
</Button>
)}
<Button variant="outline" size="icon">
<Share2 className="w-5 aspect-square" />
</Button>
<Button
onClick={toggleComments}
variant="destructive"
size="icon"
>
<Megaphone className="w-5 aspect-square" />
</Button>
</div>
{showComments && comments && comments.length > 0 && (
<CardContent className="p-4 pt-2">
<h3 className="text-lg font-semibold mb-2">Comments</h3>
{comments.map((comment) => (
<CommentItem key={comment.id} {...comment} />
))}
</CardContent>
)} */}
</CardFooter>
</>
);
Expand Down Expand Up @@ -175,7 +133,7 @@ export function RoverContentCard({
<div className="mb-4">
<div key={media}><img src={media} className="w-full h-48 object-cover rounded-md" /></div>
</div>
)} {/* Comment/action section */}
)}
</div>
</div>
)
Expand Down

0 comments on commit edb7e68

Please sign in to comment.