import { cookies } from "next/headers"; import { getFeed, getFriends, getMe, getUserProfile, Me, User, } from "@/lib/api"; 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"; import { TopFriends } from "@/components/top-friends"; import InstallPrompt from "@/components/install-prompt"; export default async function Home() { const token = (await cookies()).get("auth_token")?.value ?? null; if (token) { return ; } else { return ; } } async function FeedPage({ token }: { token: string }) { const [feedData, me] = await Promise.all([ getFeed(token), getMe(token).catch(() => null) as Promise, ]); const allThoughts = feedData.thoughts; const thoughtThreads = buildThoughtThreads(feedData.thoughts); const authors = [...new Set(allThoughts.map((t) => t.authorUsername))]; const userProfiles = await Promise.all( authors.map((username) => getUserProfile(username, token).catch(() => null)) ); const authorDetails = new Map( userProfiles .filter((u): u is User => !!u) .map((user) => [user.username, { avatarUrl: user.avatarUrl }]) ); const friends = (await getFriends(token)).users.map((user) => user.username); const shouldDisplayTopFriends = me?.topFriends && me.topFriends.length > 8; return (

Your Feed

{thoughtThreads.map((thought) => ( ))} {thoughtThreads.length === 0 && (

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

)}
); } function LandingPage() { return ( <>

Welcome to Thoughts

Throwback to the golden age of microblogging.

); }