Skip to content

Commit

Permalink
fix(comments): hide empty placeholder if can't comment
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Apr 12, 2023
1 parent 79cdbef commit eca5a8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/components/widgets/Comment/comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ import styles from './index.module.css'
import { CommentAtRender } from './renderers/comment-at'

type Id = string
export const Comments: FC = memo(() => {
const comments = useCommentCollection((state) => state.comments)
if (comments.length === 0) {
return <Empty />
}
export const Comments: FC<{ allowComment: boolean }> = memo(
({ allowComment }) => {
const comments = useCommentCollection((state) => state.comments)

return createElement(CommentList)
})
if (comments.length === 0) {
return allowComment ? <Empty /> : null
}

return createElement(CommentList)
},
)

const CommentList: FC = memo(() => {
const comments = useCommentCollection((state) => state.comments)
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const CommentWrap: FC<CommentWrapProps> = (props) => {
<span id="comment-anchor" />
{commentShow ? (
<Fragment>
<Comments />
<Comments allowComment={allowComment} />
<div className="text-center">
{pagination &&
pagination.totalPage !== 0 &&
Expand Down

0 comments on commit eca5a8a

Please sign in to comment.