1
1
"use client"
2
- << < < << < HEAD
3
- import svPost from "../../../utils/svPost"
4
- === = ===
5
2
import svPost from "@/services/svPost" ;
6
3
import svCmt from "@/services/svCmt" ;
7
- > >>> >>> 5 a06110 ( chore ( fe ) : split service )
8
4
import Link from "next/link" ;
9
5
import Comment from "@/components/Comment" ;
10
6
import Parser from 'html-react-parser'
11
- import Image from "next/image" ;
12
- import EagleEmoji from '../../../../public/eagle_emoji.png'
13
7
import CmtForm from "@/components/CmtForm" ;
14
8
import { getRelativeTime } from "@/utils/getRelativeTime" ;
15
- import axios from "axios" ;
16
9
import { GoTrash } from "react-icons/go" ;
17
- < < << << < HEAD
18
- import { useEffect } from "react" ;
19
- = === ===
20
10
import { IPost , IComment } from "@/types" ;
21
11
import LikeButton from "@/components/LikeButton" ;
22
12
import svLike from "@/services/svLike" ;
23
- > >>> >>> 5 a06110 ( chore ( fe ) : split service )
24
13
type Props = {
25
14
params : { id : string } ;
26
15
} ;
16
+ // interface getILike{
17
+ // like: number
18
+ // }
27
19
export default async function Post ( { params } : Props ) {
28
20
const id : string = params . id ;
29
- < < << << < HEAD
30
- const { getPost , getLike , getComment , delPost } = await svPost ( ) ;
31
- useEffect ( aysnc ( ) = > {
32
- const info : any = await getPost ( id ) ;
33
- const likes : any = await getLike ( id ) ;
34
- const comment : any = await getComment ( id ) ;
35
- const author_url = "/user/" + info . author . id ;
36
-
37
- } , [ ] )
38
- const handleLikeButton = async ( e : React . FormEvent ) => {
39
- e . preventDefault ( ) ;
40
- try {
41
- // Send a POST request to your FastAPI backend
42
- let token : any
43
- if ( typeof window !== 'undefined' )
44
- token = localStorage . getItem ( 'jwt' )
45
- await axios . post ( `http://spezbe.hungnq.online/likes/?post_id=${ id } ` ,
46
- {
47
- headers : {
48
- 'accept' : 'application/json' ,
49
- 'Authorization' : `Bearer ${ token } `
50
- }
51
- }
52
- ) ;
53
-
54
- // Redirect or give feedback upon success
55
- // alert('Post created successfully!');
56
- } catch ( error ) {
57
- console . error ( 'Error posting data:' , error ) ;
58
- alert ( 'Failed to create like.' ) ;
59
- }
60
- } ;
61
- const handleDelPost = async ( e : React . FormEvent ) => {
62
- let token : any
63
- = = === ==
64
21
const { getPost, delPost } = svPost ( ) ;
65
- const { getLike } = svLike ( ) ;
66
- const { getComment } = svCmt ( )
22
+ const { getComment } = svCmt ( ) ;
23
+ const { getLike } = svLike ( )
67
24
const info : IPost = await getPost ( id ) ;
68
25
const likes : number = await getLike ( id ) ;
69
26
console . log ( likes )
70
27
const comment : IComment [ ] = await getComment ( id ) ;
71
28
const author_url = "/user/" + info . author . id ;
72
29
const handleDelPost = async ( ) => {
73
30
let token : string | null = null
74
- >>> > >>> 5 a06110 ( chore ( fe ) : split service )
75
31
if ( typeof window !== 'undefined' )
76
32
token = localStorage . getItem ( 'jwt' )
77
- const deletePost :any = await delPost ( id , token ) ;
78
- console . log ( deletePost )
33
+ await delPost ( id , token ) ;
79
34
80
35
}
81
36
return (
@@ -93,32 +48,26 @@ export default async function Post({ params }: Props) {
93
48
< div className = "pl-2 text-2xl font-bold" > { info . title } </ div >
94
49
< div className = "p-2" > { Parser ( info . content ) } </ div >
95
50
< div className = "flex flex-row" >
96
- < button onClick = { handleLikeButton } className = "w-auto flex flex-row border-2 border-black rounded-full px-2" >
97
- < p className = "pt-[0.35rem]" > Ưng</ p >
98
- < Image
99
- src = { EagleEmoji }
100
- alt = "eagle_img"
101
- width = { 30 }
102
- height = { 50 } />
103
- < p className = "pt-[0.35rem]" > : { likes } </ p >
104
- </ button >
51
+ < LikeButton initialLikes = { likes } post_id = { id } />
105
52
< div className = "w-auto mt-[0.35rem] ml-5 border-2 rounded-full px-2 border-black" > Phản hồi: { comment . length } </ div >
106
- </ div >
53
+ </ div >
107
54
< CmtForm postId = { id } />
108
55
</ div >
109
56
< div className = "border-2 border-slate-950 p-2 text-black rounded shadow h-full w-1/2 space-y-5" >
110
57
< a className = "font-bold text-2xl" > Bình Loạn</ a >
111
- { comment . map ( ( e : any ) => (
58
+ { comment . map ( ( element : IComment ) => (
112
59
< Comment
113
- // author_id = {comment.author}
114
- id = { e . id }
115
- author = { e . author }
116
- content = { e . content }
117
- date = { e . created_at }
60
+ key = { element . id }
61
+ id = { element . id }
62
+ author = { element . author }
63
+ content = { element . content }
64
+ created_at = { element . created_at }
65
+ updated_at = { element . updated_at }
66
+ post_id = { element . post_id }
118
67
/>
119
68
) ) }
120
69
</ div >
121
70
</ div >
122
71
</ >
123
72
) ;
124
- }
73
+ }
0 commit comments