This repository was archived by the owner on Feb 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ export default async function PostPage({
108108 />
109109 </ div >
110110 < div className = "flex space-x-4" >
111- < PostViews meta = { post ?. meta } />
111+ < PostViews post = { post } />
112112 < FavoriteButton post = { post } />
113113 </ div >
114114 </ div >
Original file line number Diff line number Diff line change 22
33import * as React from 'react'
44
5+ import { createClient } from '@/supabase/client'
56import { LucideIcon } from '@/lib/lucide-icon'
67import { getMetaValue } from '@/lib/utils'
7- import { type PostMeta } from '@/types/database'
8+ import { type Post } from '@/types/database'
89
910interface PostViewsProps extends React . HTMLAttributes < HTMLDivElement > {
10- meta ?: PostMeta [ ]
11+ post ?: Post
1112}
1213
13- const PostViews = ( { meta, ...props } : PostViewsProps ) => {
14- const views = getMetaValue ( meta , 'views' , '0' )
14+ const PostViews = ( { post, ...props } : PostViewsProps ) => {
15+ const views = getMetaValue ( post ?. meta , 'views' , '0' )
16+ const setPostViews = React . useCallback ( async ( postid : number ) => {
17+ const supabase = createClient ( )
18+ const result = await supabase . rpc ( 'set_post_views' , { postid } )
19+ // console.log(result)
20+ } , [ ] )
21+
22+ React . useEffect ( ( ) => {
23+ if ( typeof window !== 'undefined' && post ?. id ) {
24+ setPostViews ( post ?. id )
25+ }
26+ } , [ post ?. id , setPostViews ] )
1527
1628 return (
1729 < div className = "flex items-center" { ...props } >
You can’t perform that action at this time.
0 commit comments