You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

import useSession from "hooks/use-session"
import { useRouter } from "next/router"
import React, { useEffect, useState } from "react"
import { requestApi } from "utils/axios/request"
import CommentCard from "components/comments/comment"
import { Comment } from "src/types/comments"
import { Box, Button } from "@chakra-ui/react"
const CommentPage = () => {
const router = useRouter()
const session = useSession()
const [comment,setComment]:[Comment,any] = useState(null)
useEffect(() => {
if (router.query.id) {
initData()
}
}, [router.query.id])
const initData = async () => {
const res = await requestApi.get(`/story/comment/${router.query.id}`)
res.data.replies = []
setComment(res.data)
console.log(res.data)
}
const gotoPost = async () => {
const res = await requestApi.get(`/story/byCommentID/${comment.id}`)
router.push(res.data + '#comments')
}
return (
<Box p="4">
<Button mb="2" onClick={() => gotoPost()}></Button>
{comment && session && <CommentCard user={session.user} comment={comment} onChange={null}/>}
</Box>
)
}
export default CommentPage