Skip to content

Commit b911386

Browse files
committed
feat: improve home page perf
1 parent 13dac6d commit b911386

File tree

18 files changed

+82
-229
lines changed

18 files changed

+82
-229
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ turbo dev
5353
🐴 dayjs
5454
🤗 Eslint
5555
💥 Husky
56-
👽 Prettier
56+
👽 Prettier
5757

5858
# Functions
5959

apps/web/@/actions/protect/postAction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import APP_ROUTES from "@/constants/routes"
1818
import { TUserItem, userSelect } from "@/types/users"
1919
import { getServerSession } from "@/utils/auth"
2020

21+
// TODO: move to database package
22+
// Get total actions (like, bookmark) for a post
2123
export const getTotalActions = async ({
2224
postId,
2325
actionType,

apps/web/@/actions/protect/posts.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

apps/web/@/molecules/home/filter/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import React, { useState } from "react"
44
import { usePathname, useRouter, useSearchParams } from "next/navigation"
55

6+
import { FilterValues, PeriodValues } from "database"
67
import { cn } from "ui"
78

8-
import { FilterValues, PeriodValues } from "@/types/filter"
99
import { capitalizeFirstLetter } from "@/utils/text"
1010

1111
import { FilterItem } from "./filter-item"

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import Image from "next/image"
12
import Link from "next/link"
23

4+
import { TPostItem } from "database"
35
import { Typography } from "ui"
46

57
import APP_ROUTES from "@/constants/routes"
68
import TagList from "@/molecules/tag/tag-list"
7-
import { TPostItem } from "@/types/posts"
89
import { generatePath } from "@/utils/generatePath"
910

1011
import BookmarkButton from "./bookmark-button"
@@ -38,14 +39,25 @@ export default function PostItem({ post }: { post: TPostItem }) {
3839
}}
3940
/>
4041

41-
<div className="mt-2 flex justify-between">
42+
{/* <div className="mt-2 flex justify-between">
4243
<div className="flex gap-4">
4344
<LikeButton post={post} />
4445
<CommentButton post={post} />
4546
</div>
4647
<BookmarkButton post={post} />
47-
</div>
48+
</div> */}
4849
</div>
50+
{post.Image && (
51+
<div className="flex items-center">
52+
<Image
53+
src={post.Image.url}
54+
alt={post.title}
55+
width={160}
56+
height={120}
57+
className="h-[120px] w-[160px] rounded-sm object-cover"
58+
/>
59+
</div>
60+
)}
4961
</div>
5062
)
5163
}

apps/web/@/molecules/posts/post-item/post-meta/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 dayjs from "dayjs"
56

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

1010
type PostMetaProps = {

apps/web/@/molecules/top-tags/NumberIndex.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import React from "react"
44

5-
import { useTheme } from "next-themes"
65
import { cn } from "ui"
76

87
import { bebasNeue } from "@/font"
@@ -12,12 +11,11 @@ interface NumberIndexProps {
1211
}
1312

1413
const NumberIndex: React.FC<NumberIndexProps> = ({ number }) => {
15-
// const { theme } = useTheme()
16-
1714
return (
1815
<div
1916
className={cn(
20-
"flex items-center justify-center stroke-black stroke-1 text-2xl font-extrabold"
17+
"flex items-center justify-center fill-none stroke-black stroke-1 text-2xl font-extrabold",
18+
bebasNeue.className
2119
)}
2220
>
2321
{number}.

apps/web/@/molecules/top-tags/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ import NumberIndex from "./NumberIndex"
1010
const TopTag: React.FC = async () => {
1111
const t = await getTranslations()
1212

13-
const tagData = await getTopTags({})
13+
const { data: topTags } = await getTopTags()
1414

1515
return (
1616
<div className="mt-4 border-t pt-4">
1717
<Typography variant="h3">{t("common.trending")}</Typography>
1818
<ul>
19-
{(tagData?.data || []).map((tag, index) => (
19+
{(topTags?.data || []).map((tag, index) => (
2020
<li
2121
key={tag.id}
2222
className="mb-2 flex items-center gap-2"
2323
>
2424
<NumberIndex number={index + 1} />
2525
<Link href={`/tags/${tag?.slug || tag?.id}`}>
2626
<div className="hover:underline">
27-
<strong>{tag.name}</strong>
28-
<Typography className="flex gap-1 text-xs">
29-
<strong>{tag?._count.tagOnPost}</strong>
30-
{t("common.post", {
31-
total: tag?._count.tagOnPost || 0,
27+
<Typography variant="strong">#{tag.name}</Typography>
28+
<Typography variant="mutedText">
29+
{t("common.total_post_plural", {
30+
total: tag?._count?.tagOnPost || 0,
3231
})}
3332
</Typography>
3433
</div>

apps/web/@/types/filter.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/web/@/types/posts.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)