diff --git a/app/scenes/Document/components/CommentThread.tsx b/app/scenes/Document/components/CommentThread.tsx index 832bf60e0e..940037d5dc 100644 --- a/app/scenes/Document/components/CommentThread.tsx +++ b/app/scenes/Document/components/CommentThread.tsx @@ -10,8 +10,9 @@ import { s } from "@shared/styles"; import { ProsemirrorData } from "@shared/types"; import Comment from "~/models/Comment"; import Document from "~/models/Document"; -import { Avatar } from "~/components/Avatar"; +import { Avatar, AvatarSize } from "~/components/Avatar"; import { useDocumentContext } from "~/components/DocumentContext"; +import Facepile from "~/components/Facepile"; import Fade from "~/components/Fade"; import Flex from "~/components/Flex"; import { ResizingHeightContainer } from "~/components/ResizingHeightContainer"; @@ -40,6 +41,10 @@ type Props = { enableScroll: () => void; /** Disable scroll for the comments container */ disableScroll: () => void; + /** Number of replies before collapsing */ + collapseThreshold?: number; + /** Number of replies to display when collapsed */ + collapseNumDisplayed?: number; }; function useTypingIndicator({ @@ -69,6 +74,8 @@ function CommentThread({ focused, enableScroll, disableScroll, + collapseThreshold = 5, + collapseNumDisplayed = 3, }: Props) { const [focusedOnMount] = React.useState(focused); const { editor } = useDocumentContext(); @@ -102,6 +109,17 @@ function CommentThread({ .inThread(thread.id) .filter((comment) => !comment.isNew); + const [collapse, setCollapse] = React.useState(() => { + const numReplies = commentsInThread.length - 1; + if (numReplies >= collapseThreshold) { + return { + begin: 1, + final: commentsInThread.length - collapseNumDisplayed - 1, + }; + } + return null; + }); + useOnClickOutside(topRef, (event) => { if ( focused && @@ -129,6 +147,36 @@ function CommentThread({ }); }; + const handleClickExpand = (ev: React.SyntheticEvent) => { + ev.stopPropagation(); + setCollapse(null); + }; + + const renderShowMore = (collapse: { begin: number; final: number }) => { + const count = collapse.final - collapse.begin + 1; + const createdBy = commentsInThread + .slice(collapse.begin, collapse.final + 1) + .map((c) => c.createdBy); + const users = Array.from(new Set(createdBy)); + const limit = 3; + const overflow = users.length - limit; + + return ( + + {t("Show {{ count }} reply", { count })} + ( + + )} + /> + + ); + }; + React.useEffect(() => { if (!focused && autoFocus) { setAutoFocus(false); @@ -192,8 +240,17 @@ function CommentThread({ onClick={handleClickThread} > {commentsInThread.map((comment, index) => { + if (collapse !== null) { + if (index === collapse.begin) { + return renderShowMore(collapse); + } else if (index > collapse.begin && index <= collapse.final) { + return null; + } + } + const firstOfAuthor = index === 0 || + (collapse && index === collapse.final + 1) || comment.createdById !== commentsInThread[index - 1].createdById; const lastOfAuthor = index === commentsInThread.length - 1 || @@ -276,6 +333,24 @@ const Reply = styled.button` `} `; +const ShowMore = styled.div<{ $dir?: "rtl" | "ltr" }>` + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 1px; + margin-left: ${(props) => (props.$dir === "rtl" ? 0 : 32)}px; + margin-right: ${(props) => (props.$dir !== "rtl" ? 0 : 32)}px; + padding: 8px 12px; + color: ${s("textTertiary")}; + background: ${s("backgroundTertiary")}; + cursor: var(--pointer); + font-size: 13px; + + * { + border-color: ${s("backgroundTertiary")}; + } +`; + const Thread = styled.div<{ $focused: boolean; $recessed: boolean; diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 842e768c89..9745451f83 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -602,6 +602,8 @@ "Most recent": "Most recent", "Order in doc": "Order in doc", "Resolved": "Resolved", + "Show {{ count }} reply": "Show {{ count }} reply", + "Show {{ count }} reply_plural": "Show {{ count }} replies", "Error updating comment": "Error updating comment", "Document restored": "Document restored", "Images are still uploading.\nAre you sure you want to discard them?": "Images are still uploading.\nAre you sure you want to discard them?",