-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathuser-related.tsx
More file actions
96 lines (92 loc) · 2.34 KB
/
user-related.tsx
File metadata and controls
96 lines (92 loc) · 2.34 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import type {
AuthorQueryWithRelatedResult,
GuestQueryResult,
} from "@/sanity/types";
import Link from "next/link";
import CoverImage from "@/components/cover-image";
import { Button } from "@/components/ui/button";
import { pluralize } from "@/lib/utils";
export default async function UserRelated(
related: NonNullable<AuthorQueryWithRelatedResult>["related"],
) {
if (
!related?.podcast?.length &&
!related?.post?.length
) {
return <></>;
}
const contentLinks = (
_type: string,
contents: Array<{
_id: string;
_type: string;
status: "draft" | "published";
title: string;
slug: string | null;
excerpt: string | null;
coverImage: any;
date: string;
}>,
) => {
return (
<div className="grid grid-cols-1 gap-y-20 md:grid-cols-2 md:gap-x-16 md:gap-y-32 lg:gap-x-32">
{contents?.map((post) => {
const { _id, _type, title, slug, coverImage } = post;
return (
<article key={_id}>
<Link href={`/${_type}/${slug}`} className="block mb-5 group">
<CoverImage
image={coverImage}
priority={false}
className="rounded-md"
/>
</Link>
<h3 className="mb-3 text-3xl leading-snug text-balance">
<Link href={`/${_type}/${slug}`} className="hover:underline">
{title}
</Link>
</h3>
</article>
);
})}
</div>
);
};
return (
<aside>
{Object.entries(related).map((r) => {
const _type = r.at(0) as string;
const contents = r.at(1) as Array<{
_id: string;
_type: string;
status: "draft" | "published";
title: string;
slug: string | null;
excerpt: string | null;
coverImage: any;
date: string;
}>;
if (!contents?.length) {
return <span key={_type} />;
}
return (
<section key={_type} className="flex flex-col">
<hr className="my-12 md:my-24 border-accent-2" />
<div className="flex flex-col md:flex-row md:justify-between">
<h2 className="mb-8 text-6xl font-bold leading-tight tracking-tighter md:text-7xl capitalize">
Latest {pluralize(_type)}
</h2>
<Button
asChild
className="mb-8 text-3xl font-bold md:text-4xl p-2 md:p-8"
>
<Link href="/search">Search</Link>
</Button>
</div>
{contentLinks(_type, contents)}
</section>
);
})}
</aside>
);
}