From bf2e280cdd369a640d669867775db3e53a2962d6 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 6 Sep 2025 21:02:46 +0200 Subject: [PATCH] feat: implement threaded replies and enhance feed layout with ThoughtThread component --- thoughts-frontend/app/page.tsx | 40 +++++---- .../app/users/[username]/page.tsx | 35 ++++---- thoughts-frontend/components/reply-form.tsx | 90 +++++++++++++++++++ thoughts-frontend/components/thought-card.tsx | 59 +++++++++++- .../components/thought-thread.tsx | 52 +++++++++++ thoughts-frontend/lib/utils.ts | 29 ++++++ 6 files changed, 269 insertions(+), 36 deletions(-) create mode 100644 thoughts-frontend/components/reply-form.tsx create mode 100644 thoughts-frontend/components/thought-thread.tsx diff --git a/thoughts-frontend/app/page.tsx b/thoughts-frontend/app/page.tsx index 20ee490..c5c1a33 100644 --- a/thoughts-frontend/app/page.tsx +++ b/thoughts-frontend/app/page.tsx @@ -1,11 +1,13 @@ // app/page.tsx import { cookies } from "next/headers"; -import { getFeed, getMe, getUserProfile, Me } from "@/lib/api"; +import { getFeed, getMe, getUserProfile, Me, Thought } from "@/lib/api"; import { ThoughtCard } from "@/components/thought-card"; import { PostThoughtForm } from "@/components/post-thought-form"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import { PopularTags } from "@/components/popular-tags"; +import { ThoughtThread } from "@/components/thought-thread"; +import { buildThoughtThreads } from "@/lib/utils"; // This is now an async Server Component export default async function Home() { @@ -32,6 +34,10 @@ async function FeedPage({ token }: { token: string }) { .map((user) => [user!.username, { avatarUrl: user!.avatarUrl }]) ); + const allThoughts = feedData.thoughts; + const { topLevelThoughts, repliesByParentId } = + buildThoughtThreads(allThoughts); + return (
@@ -39,22 +45,22 @@ async function FeedPage({ token }: { token: string }) {

Your Feed

- {feedData.thoughts.map((thought) => ( - - ))} - {feedData.thoughts.length === 0 && ( -

- Your feed is empty. Follow some users to see their thoughts here! -

- )} +
+ {topLevelThoughts.map((thought) => ( + + ))} + {topLevelThoughts.length === 0 && ( +

+ Your feed is empty. Follow some users to see their thoughts here! +

+ )} +