feat: refactor thought threads handling to improve structure and efficiency

This commit is contained in:
2025-09-07 15:09:45 +02:00
parent 40695b7ad3
commit 5ce6d9f2da
7 changed files with 89 additions and 90 deletions

View File

@@ -1,9 +1,8 @@
import { Me, Thought } from "@/lib/api";
import { Me, ThoughtThread as ThoughtThreadType } from "@/lib/api";
import { ThoughtCard } from "./thought-card";
interface ThoughtThreadProps {
thought: Thought;
repliesByParentId: Map<string, Thought[]>;
thought: ThoughtThreadType;
authorDetails: Map<string, { avatarUrl?: string | null }>;
currentUser: Me | null;
isReply?: boolean;
@@ -11,7 +10,6 @@ interface ThoughtThreadProps {
export function ThoughtThread({
thought,
repliesByParentId,
authorDetails,
currentUser,
isReply = false,
@@ -22,8 +20,6 @@ export function ThoughtThread({
...authorDetails.get(thought.authorUsername),
};
const directReplies = repliesByParentId.get(thought.id) || [];
return (
<div id={`thought-thread-${thought.id}`} className="flex flex-col gap-0">
<ThoughtCard
@@ -33,16 +29,15 @@ export function ThoughtThread({
isReply={isReply}
/>
{directReplies.length > 0 && (
{thought.replies.length > 0 && (
<div
id={`thought-thread-${thought.id}__replies`}
className="pl-6 border-l-2 border-primary border-dashed ml-6 flex flex-col gap-4 pt-4"
>
{directReplies.map((reply) => (
{thought.replies.map((reply) => (
<ThoughtThread // RECURSIVE CALL
key={reply.id}
thought={reply}
repliesByParentId={repliesByParentId} // Pass the full map down
authorDetails={authorDetails}
currentUser={currentUser}
isReply={true}