import React, { useState } from 'react'; import type { IUser } from '@growi/core'; import { Collapse } from 'reactstrap'; import type { RendererOptions } from '~/interfaces/renderer-options'; import type { ICommentHasId, ICommentHasIdList } from '../../interfaces/comment'; import { useIsAllReplyShown } from '../../stores/context'; import { Comment } from './Comment'; import styles from './ReplyComments.module.scss'; type ReplycommentsProps = { rendererOptions: RendererOptions, isReadOnly: boolean, revisionId: string, revisionCreatedAt: Date, currentUser: IUser, replyList: ICommentHasIdList, pageId: string, pagePath: string, deleteBtnClicked: (comment: ICommentHasId) => void, onComment: () => void, } export const ReplyComments = (props: ReplycommentsProps): JSX.Element => { const { rendererOptions, isReadOnly, revisionId, revisionCreatedAt, currentUser, replyList, pageId, pagePath, deleteBtnClicked, onComment, } = props; const { data: isAllReplyShown } = useIsAllReplyShown(); const [isOlderRepliesShown, setIsOlderRepliesShown] = useState(false); const renderReply = (reply: ICommentHasId) => { return (
); }; if (isAllReplyShown) { return ( <> {replyList.map((reply) => { return renderReply(reply); })} ); } const areThereHiddenReplies = (replyList.length > 2); const toggleButtonIconName = isOlderRepliesShown ? 'expand_less' : 'more_vert'; const toggleButtonIcon = {toggleButtonIconName}; const toggleButtonLabel = isOlderRepliesShown ? '' : 'more'; const shownReplies = replyList.slice(replyList.length - 2, replyList.length); const hiddenReplies = replyList.slice(0, replyList.length - 2); const hiddenElements = hiddenReplies.map((reply) => { return renderReply(reply); }); const shownElements = shownReplies.map((reply) => { return renderReply(reply); }); return ( <> {areThereHiddenReplies && (
{hiddenElements}
)} {shownElements} ); };