diff --git a/packages/app/src/components/CommentsCard/index.jsx b/packages/app/src/components/CommentsCard/index.jsx new file mode 100644 index 00000000..7ff8fb3f --- /dev/null +++ b/packages/app/src/components/CommentsCard/index.jsx @@ -0,0 +1,86 @@ +import React from "react" +import * as antd from "antd" +import moment from "moment" + +import { CommentCreator } from "components" + +import "./index.less" + +export default (props) => { + const [postData, setPostData] = React.useState(null) + const [comments, setComments] = React.useState(null) + + const fetchData = async () => { + setPostData(null) + setComments(null) + + // fetch post data + const postDataResult = await window.app.api.request("main", "get", `post`, undefined, { + post_id: props.post_id + }).catch((err) => { + console.log(err) + + antd.message.error("Failed to fetch post data") + + return null + }) + + if (!postDataResult) return + + setPostData(postDataResult) + + // fetch comments + const commentsResult = await window.app.api.customRequest("main", { + method: "get", + url: `/post/${props.post_id}/comments`, + }).catch((err) => { + console.log(err) + + antd.message.error("Failed to fetch comments") + + return null + }) + + console.log(commentsResult) + + if (!commentsResult) return + + setComments(commentsResult.data) + } + + React.useEffect(() => { + fetchData() + }, []) + + const renderComments = () => { + return comments.map((comment) => { + return