@@ -9,22 +9,26 @@ import CmtForm from "@/components/CmtForm";
9
9
import { getRelativeTime } from "@/utils/getRelativeTime" ;
10
10
import axios from "axios" ;
11
11
import { GoTrash } from "react-icons/go" ;
12
+ import { IPost , IComment } from "@/types" ;
12
13
type Props = {
13
14
params : { id : string } ;
14
15
} ;
16
+ interface getILike {
17
+ like : number
18
+ }
15
19
export default async function Post ( { params } : Props ) {
16
20
const id : string = params . id ;
17
21
const { getPost, getLike, getComment, delPost } = svPost ( ) ;
18
22
19
- const info : any = await getPost ( id ) ;
20
- const likes : any = await getLike ( id ) ;
21
- const comment : any = await getComment ( id ) ;
23
+ const info : IPost = await getPost ( id ) ;
24
+ const likes : getILike = await getLike ( id ) ;
25
+ const comment : IComment [ ] = await getComment ( id ) ;
22
26
const author_url = "/user/" + info . author . id ;
23
27
const handleLikeButton = async ( e : React . FormEvent ) => {
24
28
e . preventDefault ( ) ;
25
29
try {
26
30
// Send a POST request to your FastAPI backend
27
- let token : any
31
+ let token : string | null
28
32
if ( typeof window !== 'undefined' )
29
33
token = localStorage . getItem ( 'jwt' )
30
34
await axios . post ( `http://localhost:8000/likes/?post_id=${ id } ` ,
@@ -43,11 +47,11 @@ export default async function Post({ params }: Props) {
43
47
alert ( 'Failed to create like.' ) ;
44
48
}
45
49
} ;
46
- const handleDelPost = async ( e : React . FormEvent ) => {
47
- let token : any
50
+ const handleDelPost = async ( ) => {
51
+ let token : string | null
48
52
if ( typeof window !== 'undefined' )
49
53
token = localStorage . getItem ( 'jwt' )
50
- const deletePost :any = await delPost ( id , token ) ;
54
+ const deletePost :string = await delPost ( id , token ) ;
51
55
console . log ( deletePost )
52
56
53
57
}
@@ -73,21 +77,23 @@ export default async function Post({ params }: Props) {
73
77
alt = "eagle_img"
74
78
width = { 30 }
75
79
height = { 50 } />
76
- < p className = "pt-[0.35rem]" > : { likes } </ p >
80
+ < p className = "pt-[0.35rem]" > : { likes . like } </ p >
77
81
</ button >
78
82
< div className = "w-auto mt-[0.35rem] ml-5 border-2 rounded-full px-2 border-black" > Phản hồi: { comment . length } </ div >
79
83
</ div >
80
84
< CmtForm postId = { id } />
81
85
</ div >
82
86
< div className = "border-2 border-slate-950 p-2 text-black rounded shadow h-full w-1/2 space-y-5" >
83
87
< a className = "font-bold text-2xl" > Bình Loạn</ a >
84
- { comment . map ( ( e : any ) => (
88
+ { comment . map ( ( element : IComment ) => (
85
89
< Comment
86
- // author_id = {comment.author}
87
- id = { e . id }
88
- author = { e . author }
89
- content = { e . content }
90
- date = { e . created_at }
90
+ key = { element . id }
91
+ id = { element . id }
92
+ author = { element . author }
93
+ content = { element . content }
94
+ created_at = { element . created_at }
95
+ updated_at = { element . updated_at }
96
+ post_id = { element . post_id }
91
97
/>
92
98
) ) }
93
99
</ div >
0 commit comments