Repository navigation
Expand file tree
/
Copy pathTrendingPosts.tsx
More file actions
74 lines (69 loc) · 2.11 KB
/
Copy pathTrendingPosts.tsx
File metadata and controls
74 lines (69 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Link from "next/link";
import { getUnifiedTrending } from "@/server/lib/posts";
import { type Session } from "next-auth";
import { UnifiedContentCard } from "@/components/UnifiedContentCard";
type TrendingPostsProps = {
session: Session | null;
};
export default async function TrendingPosts({ session }: TrendingPostsProps) {
const userId = session?.user?.id ?? undefined;
const trendingItems = await getUnifiedTrending({
currentUserId: userId,
limit: 20,
});
if (!trendingItems) {
return (
<div className="relative mt-4 text-lg font-semibold md:col-span-7">
Something went wrong... Please refresh the page.
</div>
);
}
return (
<div className="relative md:col-span-7">
<section>
{trendingItems.map((item) => {
const isPost = item.type === "post";
return (
<UnifiedContentCard
key={`${item.type}-${item.id}`}
type={isPost ? "POST" : "LINK"}
id={item.id}
title={item.title}
excerpt={item.excerpt}
slug={item.slug}
imageUrl={item.imageUrl}
externalUrl={item.externalUrl}
publishedAt={item.publishedAt}
readTimeMins={item.readTimeMins}
upvotes={item.upvotes}
downvotes={item.downvotes}
author={
isPost
? {
name: item.authorName || "",
username: item.username || "",
image: item.authorImage,
}
: null
}
source={
!isPost
? {
name: item.sourceName || "",
slug: item.sourceSlug || null,
logo: item.sourceImage,
}
: null
}
/>
);
})}
</section>
<div className="mt-6">
<Link className="secondary-button block w-full text-center" href="/">
View Feed →
</Link>
</div>
</div>
);
}