Skip to content

Commit beb0c53

Browse files
committed
feat: update tag detail page
1 parent 10e7893 commit beb0c53

File tree

8 files changed

+43
-31
lines changed

8 files changed

+43
-31
lines changed

apps/web/@/molecules/posts/post-detail/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export default function PostDetail({ post }: PostDetailProps) {
3838
<PostMeta post={post} />
3939

4040
<TagListMeta
41-
tags={post?.tagOnPost}
41+
tags={post?.tagOnPost?.map((tag) => ({
42+
id: tag.tag.id,
43+
slug: tag.tag.slug,
44+
name: tag.tag.name,
45+
}))}
4246
classes={{
4347
container: "mt-4",
4448
}}

apps/web/@/molecules/posts/post-item/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import PostMeta from "./post-meta"
1515

1616
export default function PostItem({ post }: { post: TPostItem }) {
1717
const t = useTranslations("common")
18+
console.log(post)
1819

1920
return (
2021
<div className="mb-4 flex rounded-sm border px-8 py-4">
@@ -35,7 +36,7 @@ export default function PostItem({ post }: { post: TPostItem }) {
3536
<PostMeta post={post} />
3637

3738
<TagListMeta
38-
tags={post?.tagOnPost}
39+
tags={post?.tagOnPost?.map((tag) => tag?.tag)}
3940
classes={{
4041
container: "mt-2",
4142
}}

apps/web/@/molecules/posts/post-list/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import React, { useCallback, useState } from "react"
44
import { useParams } from "next/navigation"
55

66
import { getPosts, TGetPostsRequest, TPostItem } from "database"
7+
import { cn } from "ui"
78

89
import InfiniteScroll from "@/molecules/infinite-scroll"
910

1011
import PostItem from "../post-item"
1112

1213
export type TPostListProps = {
1314
getPostParams?: TGetPostsRequest
15+
containerClassName?: string
1416
}
1517

16-
export default function PostList({ getPostParams = {} }: TPostListProps) {
18+
export default function PostList({ getPostParams = {}, containerClassName }: TPostListProps) {
1719
const searchParams = useParams()
1820
const [isLoading, setIsLoading] = useState(false)
1921
const [posts, setPosts] = useState<TPostItem[]>([])
@@ -37,7 +39,7 @@ export default function PostList({ getPostParams = {} }: TPostListProps) {
3739
}, [searchParams, page])
3840

3941
return (
40-
<div className="mt-4">
42+
<div className={cn("mt-4", containerClassName)}>
4143
<InfiniteScroll
4244
loading={isLoading}
4345
nextPage={loadPosts}

apps/web/@/molecules/tag/tag-badge/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const TagBadge: React.FC<TagBadgeProps> = ({ tag }) => {
2020
<Link
2121
key={tag.id}
2222
href={generatePath(APP_ROUTES.TAG, {
23-
tagId: tag.slug,
23+
tagId: tag.slug || tag.id,
2424
})}
2525
>
2626
<Badge

apps/web/@/molecules/tag/tag-detail/index.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import Link from "next/link"
2+
import { notFound } from "next/navigation"
23

3-
import { TTagItem } from "database"
4+
import { getTag } from "database"
45
import { Tag } from "lucide-react"
5-
import { Button, Card, CardContent, CardHeader } from "ui"
6+
import { getTranslations } from "next-intl/server"
7+
import { Button, Card, CardContent, CardHeader, Typography } from "ui"
68

7-
export type TagDetailProp = {
8-
tag: TTagItem
9-
}
9+
export default async function TagDetail({ tagIdOrSlug }: { tagIdOrSlug: string }) {
10+
const t = await getTranslations()
11+
12+
const { data: tag, error } = await getTag({
13+
tagIdOrSlug,
14+
})
15+
16+
if (error) {
17+
return notFound()
18+
}
1019

11-
const TagDetail = ({ tag }: TagDetailProp) => {
1220
return (
1321
<div className="col-span-4">
1422
<Card>
@@ -19,9 +27,9 @@ const TagDetail = ({ tag }: TagDetailProp) => {
1927
</CardHeader>
2028
<CardContent>
2129
<div className="flex flex-col items-center justify-center gap-2">
22-
<h1 className="flex-1 text-center text-4xl font-extrabold text-slate-700">
30+
<Typography variant="h1">
2331
<Link href={`/tags/${tag?.slug || tag?.id}`}>{tag.name}</Link>
24-
</h1>
32+
</Typography>
2533
<div className="mt-4 flex w-full flex-1 divide-x">
2634
<div className="flex flex-1 flex-col items-center justify-center">
2735
<div className="font-bold text-slate-800">{tag?._count?.tagOnPost || 0}</div>
@@ -40,13 +48,11 @@ const TagDetail = ({ tag }: TagDetailProp) => {
4048
className="mt-4 w-full"
4149
variant="outline"
4250
>
43-
Follow
51+
{t("common.follow")}
4452
</Button>
4553
</div>
4654
</CardContent>
4755
</Card>
4856
</div>
4957
)
5058
}
51-
52-
export default TagDetail

apps/web/@/molecules/tag/tag-list-meta/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { cn } from "ui"
66
import TagBadge from "../tag-badge"
77

88
export type TagListProps = {
9-
tags: TTagItem[]
9+
tags: Pick<TTagItem, "id" | "name" | "slug">[]
1010
classes?: {
1111
container?: string
1212
}

apps/web/app/[lang]/(public-fullwidth)/posts/[postId]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export default async function Page({
3333
const post = await getPost({ postIdOrSlug: params?.postId })
3434
const session = await getServerSession()
3535

36-
console.log(">>>>", post)
37-
3836
if (
3937
!post ||
4038
(post.data?.postStatus === PostStatus.DRAFT && session?.user?.id !== post?.data?.author?.id)

apps/web/app/[lang]/(public-fullwidth)/tags/[tagId]/page.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import { getPosts, getTag } from "database"
1+
import { getTag } from "database"
22

3-
import { DEFAULT_PAGE_LIMIT } from "@/constants"
4-
import NoItemFounded from "@/molecules/no-item-founded"
5-
import TagPagination from "@/molecules/pagination"
6-
import PostItem from "@/molecules/posts/post-item"
73
import PostList from "@/molecules/posts/post-list"
84
import TagDetail from "@/molecules/tag/tag-detail"
95

10-
export const metadata = {
11-
title: "Tags",
12-
description: "A list of tags used in the blog posts",
6+
export const generateMetadata = async ({ params }) => {
7+
const { data: tag, error } = await getTag({
8+
tagIdOrSlug: params?.tagId,
9+
})
10+
11+
return {
12+
title: tag?.name,
13+
description: tag?.description,
14+
}
1315
}
1416

1517
export default async function Page({ searchParams, params }) {
16-
console.log(params?.tagId)
17-
1818
return (
1919
<div className="grid grid-cols-12 gap-10">
20-
{/* <TagDetail /> */}
20+
<TagDetail tagIdOrSlug={params?.tagId} />
2121

2222
<PostList
23+
containerClassName="col-span-8 mt-0"
2324
getPostParams={{
24-
tag: "reactjs",
25+
tag: params?.tagId,
2526
}}
2627
/>
2728
</div>

0 commit comments

Comments
 (0)