Skip to content

Commit 1a71621

Browse files
Pjaijaipauljaijai
andauthored
Release v1.25.0 (#420)
* Fix/ yoe slider (#408) * chore(release): 1.23.2 * fix: fix slider showing zero value * Revert "chore(release): 1.23.2" This reverts commit 28d3a11. --------- Co-authored-by: Pjaijai <paul6a24@hotmail.com> * Feature/enhance query frontend cache (#413) * chore(release): 1.23.3 * fix: fix not sliding thumb not showing (#407) Co-authored-by: Pjaijai <paul6a24@hotmail.com> * perf: longer search post and user staletime --------- Co-authored-by: Pjaijai <paul6a24@hotmail.com> * feat: add view count to post (#419) Co-authored-by: Pjaijai <paul6a24@hotmail.com> * style: fix view count border * chore(release): 1.25.0 --------- Co-authored-by: Pjaijai <paul6a24@hotmail.com>
1 parent 876a2e6 commit 1a71621

File tree

9 files changed

+667
-10
lines changed

9 files changed

+667
-10
lines changed

CHANGELOG.md

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

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [1.25.0](https://github.com/Pjaijai/Referalah/compare/v1.24.0...v1.25.0) (2025-01-29)
6+
7+
8+
### Features
9+
10+
* add view count to post ([#419](https://github.com/Pjaijai/Referalah/issues/419)) ([6fff3ad](https://github.com/Pjaijai/Referalah/commit/6fff3ad6cc5031d428c18611dbc6692f0ec664db))
11+
512
## [1.24.0](https://github.com/Pjaijai/Referalah/compare/v1.21.1...v1.24.0) (2025-01-22)
613

714

client/.env.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ NEXT_PUBLIC_SUPABASE_URL= http://localhost:54321
22
NEXT_PUBLIC_SUPABASE_ANON_KEY=
33
NEXT_PUBLIC_WEB_URL=http://localhost:3000
44
NEXT_PUBLIC_GA_MEASUREMENT_ID=
5+
NEXT_PUBLIC_FIREBASE_API_KEY=
6+
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
7+
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
8+
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
9+
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
10+
NEXT_PUBLIC_FIREBASE_APP_ID=
11+
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=

client/app/[locale]/post/view/[uuid]/page.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from "react"
22
import ReferralPostDetailsPageTemplate from "@/modules/post/view/template"
3-
import { getPostByUuid } from "@/utils/common/api"
3+
import {
4+
getPostByUuid,
5+
getPostViewCountByUuid,
6+
incrementPostViewCountByUuid,
7+
} from "@/utils/common/api"
48
import { getI18n } from "@/utils/services/internationalization/server"
59

610
import { EPostType } from "@/types/common/post-type"
@@ -44,12 +48,20 @@ export async function generateMetadata({
4448
}
4549
}
4650

47-
export const fetchCache = "default-cache"
51+
const RefererPostDetailsPage = async ({
52+
params,
53+
}: {
54+
params: { uuid: string }
55+
}) => {
56+
await incrementPostViewCountByUuid(params.uuid)
57+
const viewCount = await getPostViewCountByUuid(params.uuid)
4858

49-
const RefererPostDetailsPage = ({ params }: { params: { uuid: string } }) => {
5059
return (
5160
<CommonPageLayout>
52-
<ReferralPostDetailsPageTemplate postUuid={params.uuid} />
61+
<ReferralPostDetailsPageTemplate
62+
postUuid={params.uuid}
63+
viewCount={viewCount}
64+
/>
5365
</CommonPageLayout>
5466
)
5567
}

client/modules/post/view/template.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import PageStatusLayout from "@/components/layouts/page-status"
3434

3535
interface ReferralPostDetailsPageProps {
3636
postUuid: string | null
37+
viewCount: number | undefined
3738
}
3839
const ReferralPostDetailsPageTemplate: React.FunctionComponent<
3940
ReferralPostDetailsPageProps
40-
> = ({ postUuid }) => {
41+
> = ({ postUuid, viewCount }) => {
4142
const t = useI18n()
4243
const { data: post, isLoading, isSuccess } = useGetPost(postUuid)
4344
const userUuid = useUserStore((state) => state.uuid)
@@ -53,10 +54,13 @@ const ReferralPostDetailsPageTemplate: React.FunctionComponent<
5354
>
5455
<div className="flex flex-row items-center justify-end">
5556
<div className="flex flex-row items-end justify-center gap-4">
57+
<div className="just flex flex-row items-center gap-1 rounded-2xl border border-muted-foreground px-2 text-sm text-muted-foreground">
58+
{viewCount || "???"}
59+
<Icons.eye />
60+
</div>
5661
<div className="flex md:hidden">
5762
<LinkShareDrawer />
5863
</div>
59-
6064
<div className="hidden md:block">
6165
<BaseClipboard
6266
className="flex flex-row items-center justify-center space-x-1 border-b border-muted-foreground text-sm"

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"dayjs": "^1.11.9",
6060
"embla-carousel-autoplay": "^8.0.0",
6161
"embla-carousel-react": "^8.0.0",
62+
"firebase": "11.2.0",
6263
"framer-motion": "11.0.15",
6364
"jest-environment-jsdom": "29.7.0",
6465
"jest-runner-groups": "2.2.0",

client/utils/common/api/index.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
import { fireStore, firebase } from "@/utils/services/firebase/config"
12
import { supabase } from "@/utils/services/supabase/config"
3+
import {
4+
doc,
5+
getDoc,
6+
getFirestore,
7+
increment,
8+
setDoc,
9+
updateDoc,
10+
} from "firebase/firestore"
211

312
import { IResetPasswordRequest } from "@/types/api/request/auth/reset-password"
413
import { ISignInEmailPasswordRequest } from "@/types/api/request/auth/sign-in-with-email-password"
@@ -579,6 +588,46 @@ export const ListPostByUserUuid = async (
579588
}
580589
}
581590

591+
export const incrementPostViewCountByUuid = async (postUuid: string) => {
592+
const postRef = doc(fireStore, "postViewCount", postUuid)
593+
594+
try {
595+
const docSnap = await getDoc(postRef)
596+
597+
if (!docSnap.exists()) {
598+
// Document doesn't exist, create it with initial view count of 1
599+
await setDoc(postRef, { viewCount: 1 })
600+
return { viewCount: 1 }
601+
} else {
602+
// Document exists, increment the view count
603+
const updateResult = await updateDoc(postRef, {
604+
viewCount: increment(1),
605+
})
606+
607+
return updateResult
608+
}
609+
} catch (error) {
610+
throw error
611+
}
612+
}
613+
614+
export const getPostViewCountByUuid = async (
615+
postUuid: string
616+
): Promise<number | undefined> => {
617+
const postRef = doc(fireStore, "postViewCount", postUuid)
618+
619+
try {
620+
const docSnap = await getDoc(postRef)
621+
if (docSnap.exists()) {
622+
return docSnap.data().viewCount || 0
623+
} else {
624+
return 0
625+
}
626+
} catch (error) {
627+
return undefined
628+
}
629+
}
630+
582631
// Industry
583632
export const getIndustryList = async () => {
584633
try {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { initializeApp } from "firebase/app"
2+
import { getFirestore } from "firebase/firestore"
3+
4+
const firebaseConfig = {
5+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
6+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
7+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
8+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
9+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
10+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
11+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
12+
}
13+
const app = initializeApp(firebaseConfig)
14+
const firebase = initializeApp(firebaseConfig)
15+
const fireStore = getFirestore(app)
16+
export { firebase, fireStore }

0 commit comments

Comments
 (0)