@@ -4,56 +4,31 @@ import Link from "next/link";
4
4
import Comment from "@/components/Comment" ;
5
5
import Parser from 'html-react-parser'
6
6
import Image from "next/image" ;
7
- import EagleEmoji from '../../../../public/eagle_emoji.png'
8
7
import CmtForm from "@/components/CmtForm" ;
9
8
import { getRelativeTime } from "@/utils/getRelativeTime" ;
10
- import axios from "axios" ;
11
9
import { GoTrash } from "react-icons/go" ;
12
10
import { IPost , IComment } from "@/types" ;
11
+ import LikeButton from "@/components/LikeButton" ;
13
12
type Props = {
14
13
params : { id : string } ;
15
14
} ;
16
- interface getILike {
17
- like : number
18
- }
15
+ // interface getILike{
16
+ // like: number
17
+ // }
19
18
export default async function Post ( { params } : Props ) {
20
19
const id : string = params . id ;
21
20
const { getPost, getLike, getComment, delPost } = svPost ( ) ;
22
21
23
22
const info : IPost = await getPost ( id ) ;
24
- const likes : getILike = await getLike ( id ) ;
23
+ const likes : number = await getLike ( id ) ;
24
+ console . log ( likes )
25
25
const comment : IComment [ ] = await getComment ( id ) ;
26
26
const author_url = "/user/" + info . author . id ;
27
- const handleLikeButton = async ( e : React . FormEvent ) => {
28
- e . preventDefault ( ) ;
29
- try {
30
- // Send a POST request to your FastAPI backend
31
- let token : string | null = null
32
- if ( typeof window !== 'undefined' )
33
- token = localStorage . getItem ( 'jwt' )
34
- await axios . post ( `http://localhost:8000/likes/?post_id=${ id } ` ,
35
- {
36
- headers : {
37
- 'accept' : 'application/json' ,
38
- /* eslint-disable @typescript-eslint/no-use-before-define */
39
- 'Authorization' : `Bearer ${ token } `
40
- }
41
- }
42
- ) ;
43
-
44
- // Redirect or give feedback upon success
45
- // alert('Post created successfully!');
46
- } catch ( error ) {
47
- console . error ( 'Error posting data:' , error ) ;
48
- alert ( 'Failed to create like.' ) ;
49
- }
50
- } ;
51
27
const handleDelPost = async ( ) => {
52
28
let token : string | null = null
53
29
if ( typeof window !== 'undefined' )
54
30
token = localStorage . getItem ( 'jwt' )
55
- const deletePost :string = await delPost ( id , token ) ;
56
- console . log ( deletePost )
31
+ await delPost ( id , token ) ;
57
32
58
33
}
59
34
return (
@@ -71,17 +46,9 @@ export default async function Post({ params }: Props) {
71
46
< div className = "pl-2 text-2xl font-bold" > { info . title } </ div >
72
47
< div className = "p-2" > { Parser ( info . content ) } </ div >
73
48
< div className = "flex flex-row" >
74
- < button onClick = { handleLikeButton } className = "w-auto flex flex-row border-2 border-black rounded-full px-2" >
75
- < p className = "pt-[0.35rem]" > Ưng</ p >
76
- < Image
77
- src = { EagleEmoji }
78
- alt = "eagle_img"
79
- width = { 30 }
80
- height = { 50 } />
81
- < p className = "pt-[0.35rem]" > : { likes . like } </ p >
82
- </ button >
49
+ < LikeButton initialLikes = { likes } post_id = { id } />
83
50
< div className = "w-auto mt-[0.35rem] ml-5 border-2 rounded-full px-2 border-black" > Phản hồi: { comment . length } </ div >
84
- </ div >
51
+ </ div >
85
52
< CmtForm postId = { id } />
86
53
</ div >
87
54
< div className = "border-2 border-slate-950 p-2 text-black rounded shadow h-full w-1/2 space-y-5" >
0 commit comments