Skip to content

Commit ac94b08

Browse files
committed
feat: update query for home page
1 parent 98948fb commit ac94b08

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from "react"
22

3-
import { PostOnUserType } from "database"
3+
import { PostOnUserType, TPostItem } from "database"
44

55
import { getTotalActions } from "@/actions/protect/postAction"
6-
import { TPostItem } from "@/types/posts"
76

87
import BookmarkButton from "./BookmarkButton"
98

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react"
22
import Link from "next/link"
33

4+
import { TPostItem } from "database"
45
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "ui"
56

67
import APP_ROUTES from "@/constants/routes"
7-
import { TPostItem } from "@/types/posts"
88
import { generatePath } from "@/utils/generatePath"
99

1010
type CommentButtonProps = {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ export default function PostItem({ post }: { post: TPostItem }) {
4242
}}
4343
/>
4444

45-
{/* <div className="mt-2 flex justify-between">
45+
<div className="mt-2 flex justify-between">
4646
<div className="flex gap-4">
4747
<LikeButton post={post} />
4848
<CommentButton post={post} />
4949
</div>
50-
<BookmarkButton post={post} />
51-
</div> */}
50+
</div>
5251
</div>
5352
{post.Image && (
5453
<div className="flex items-center">

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { TPostItem } from "database"
12
import { useTranslations } from "next-intl"
23
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Typography } from "ui"
34

4-
import { TPostItem } from "@/types/posts"
5-
65
type LikeButtonProps = {
76
post: TPostItem
87
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type PostMetaProps = {
1212
}
1313

1414
const PostMeta: React.FC<PostMetaProps> = ({ post }) => {
15+
if (!post?.author) return null
16+
1517
return (
1618
<div className="mt-2 flex items-center gap-2 text-xs text-gray-400">
1719
<div className="text hover:underline">

apps/web/app/[lang]/(public)/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export default async function Page({
1515
}: {
1616
searchParams: { [key: string]: string | string[] | undefined }
1717
}) {
18-
const posts = await getPosts(searchParams)
18+
const posts = await getPosts({
19+
...searchParams,
20+
postStatus: PostStatus.PUBLISHED,
21+
})
1922

2023
return (
2124
<div className="">

packages/database/src/posts/queries.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const getPost = async ({
4545
}
4646
}
4747

48-
export const getPosts = async ({ searchParams }: TGetPostsRequest): Promise<TGetPostsResponse> => {
48+
export const getPosts = async (searchParams: TGetPostsRequest): Promise<TGetPostsResponse> => {
4949
const searchTerm = searchParams?.search || ""
5050
const tag = searchParams?.tag || ""
5151
const filter = searchParams?.filter || FilterValues.LASTED // lasted or hot
@@ -144,7 +144,9 @@ export const getPosts = async ({ searchParams }: TGetPostsRequest): Promise<TGet
144144
prisma.post.count({ where }),
145145
prisma.post.findMany({
146146
where,
147-
select: postSelect,
147+
select: {
148+
...postSelect,
149+
},
148150
take: Number(limit),
149151
skip: (Number(page) - 1) * Number(limit),
150152
orderBy,
@@ -153,8 +155,8 @@ export const getPosts = async ({ searchParams }: TGetPostsRequest): Promise<TGet
153155

154156
return {
155157
data: {
156-
data: posts,
157158
total,
159+
data: posts,
158160
page: Number(page),
159161
limit: Number(limit),
160162
totalPages: Math.ceil(total / Number(limit)),

packages/database/src/posts/selects.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,12 @@ export const postSelect = {
2424
image: true,
2525
},
2626
},
27-
postOnUser: {
27+
_count: {
2828
select: {
29-
type: true,
30-
userId: true,
31-
postId: true,
29+
comments: true,
30+
postOnUser: true,
3231
},
3332
},
34-
// _count: {
35-
// select: {
36-
// comments: true,
37-
// postOnUser: true,
38-
// },
39-
// },
4033
tagOnPost: {
4134
select: {
4235
tag: {

packages/database/src/posts/type.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import { TPostItem } from "./selects"
66
export type TGetPostsResponse = IActionReturn<IGetListResponse<TPostItem>>
77

88
export type TGetPostsRequest = {
9-
searchParams: {
10-
query?: string
11-
search?: string
12-
tag?: string
13-
filter?: string
14-
period?: string
15-
limit?: string
16-
page?: string
17-
authorId?: string
18-
postStatus?: PostStatus
19-
}
9+
query?: string
10+
search?: string
11+
tag?: string
12+
filter?: string
13+
period?: string
14+
limit?: string
15+
page?: string
16+
authorId?: string
17+
postStatus?: PostStatus
2018
}

0 commit comments

Comments
 (0)