From 63ec7daa7a32e4bad36a87e210649aa5058f88cf Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 7 Mar 2023 02:10:26 +0000 Subject: [PATCH] improve component layout --- .../app/src/components/CommentsCard/index.jsx | 34 ++-- .../src/components/CommentsCard/index.less | 12 ++ .../actions/commentsButton/index.jsx | 2 +- .../PostCard/components/actions/index.jsx | 69 +++++++- .../PostCard/components/attachments/index.jsx | 8 +- .../PostCard/components/content/index.jsx | 75 --------- .../PostCard/components/content/index.less | 81 ---------- .../app/src/components/PostCard/index.jsx | 149 +++++++++++------- .../app/src/components/PostCard/index.less | 97 +++++++++++- 9 files changed, 288 insertions(+), 239 deletions(-) delete mode 100755 packages/app/src/components/PostCard/components/content/index.jsx delete mode 100755 packages/app/src/components/PostCard/components/content/index.less diff --git a/packages/app/src/components/CommentsCard/index.jsx b/packages/app/src/components/CommentsCard/index.jsx index 57e638f2..0e00a4cf 100755 --- a/packages/app/src/components/CommentsCard/index.jsx +++ b/packages/app/src/components/CommentsCard/index.jsx @@ -1,5 +1,6 @@ import React from "react" import * as antd from "antd" +import classnames from "classnames" import moment from "moment" import { Icons } from "components/Icons" @@ -48,11 +49,10 @@ const CommentCard = (props) => { } export default (props) => { + const [visible, setVisible] = React.useState(props.visible ?? true) const [comments, setComments] = React.useState(null) const fetchData = async () => { - setComments(null) - // fetch comments const commentsResult = await PostModel.getPostComments({ post_id: props.post_id @@ -123,9 +123,19 @@ export default (props) => { } React.useEffect(() => { - fetchData() - listenEvents() + setVisible(props.visible) + }, [props.visible]) + React.useEffect(() => { + if (visible) { + fetchData() + listenEvents() + } else { + unlistenEvents() + } + }, [visible]) + + React.useEffect(() => { return () => { unlistenEvents() } @@ -149,17 +159,23 @@ export default (props) => { }) } - if (!comments) { - return - } - - return
+ return

Comments

+ {renderComments()} +
{