fix: Unable to scroll until multiple comments (#7112)

* fix: Unable to scroll in comments
fix: Missing highlighted text on first comment while composing

* docs
This commit is contained in:
Tom Moor
2024-06-22 10:05:23 -04:00
committed by GitHub
parent d8f14377f8
commit eaab97dcbf
5 changed files with 43 additions and 27 deletions

View File

@@ -24,6 +24,7 @@ import useOnClickOutside from "~/hooks/useOnClickOutside";
import useStores from "~/hooks/useStores"; import useStores from "~/hooks/useStores";
import CommentEditor from "./CommentEditor"; import CommentEditor from "./CommentEditor";
import { Bubble } from "./CommentThreadItem"; import { Bubble } from "./CommentThreadItem";
import { HighlightedText } from "./HighlightText";
type Props = { type Props = {
/** Callback when the draft should be saved. */ /** Callback when the draft should be saved. */
@@ -42,6 +43,8 @@ type Props = {
standalone?: boolean; standalone?: boolean;
/** Whether to animate the comment form in and out */ /** Whether to animate the comment form in and out */
animatePresence?: boolean; animatePresence?: boolean;
/** Text to highlight at the top of the comment */
highlightedText?: string;
/** The text direction of the editor */ /** The text direction of the editor */
dir?: "rtl" | "ltr"; dir?: "rtl" | "ltr";
/** Callback when the user is typing in the editor */ /** Callback when the user is typing in the editor */
@@ -64,6 +67,7 @@ function CommentForm({
standalone, standalone,
placeholder, placeholder,
animatePresence, animatePresence,
highlightedText,
dir, dir,
...rest ...rest
}: Props) { }: Props) {
@@ -274,6 +278,9 @@ function CommentForm({
$firstOfThread={standalone} $firstOfThread={standalone}
column column
> >
{highlightedText && (
<HighlightedText>{highlightedText}</HighlightedText>
)}
<CommentEditor <CommentEditor
key={`${forceRender}`} key={`${forceRender}`}
ref={editorRef} ref={editorRef}

View File

@@ -210,6 +210,9 @@ function CommentThread({
standalone={commentsInThread.length === 0} standalone={commentsInThread.length === 0}
dir={document.dir} dir={document.dir}
autoFocus={autoFocus} autoFocus={autoFocus}
highlightedText={
commentsInThread.length === 0 ? highlightedText : undefined
}
/> />
</Fade> </Fade>
)} )}

View File

@@ -19,8 +19,9 @@ import Text from "~/components/Text";
import Time from "~/components/Time"; import Time from "~/components/Time";
import useBoolean from "~/hooks/useBoolean"; import useBoolean from "~/hooks/useBoolean";
import CommentMenu from "~/menus/CommentMenu"; import CommentMenu from "~/menus/CommentMenu";
import { hover, truncateMultiline } from "~/styles"; import { hover } from "~/styles";
import CommentEditor from "./CommentEditor"; import CommentEditor from "./CommentEditor";
import { HighlightedText } from "./HighlightText";
/** /**
* Hook to calculate if we should display a timestamp on a comment * Hook to calculate if we should display a timestamp on a comment
@@ -127,12 +128,12 @@ function CommentThreadItem({
const handleCancel = () => { const handleCancel = () => {
setData(toJS(comment.data)); setData(toJS(comment.data));
setReadOnly(); setReadOnly();
setForceRender((s) => ++s); setForceRender((i) => ++i);
}; };
React.useEffect(() => { React.useEffect(() => {
setData(toJS(comment.data)); setData(toJS(comment.data));
setForceRender((s) => ++s); setForceRender((i) => ++i);
}, [comment.data]); }, [comment.data]);
return ( return (
@@ -240,28 +241,6 @@ const Body = styled.form`
border-radius: 2px; border-radius: 2px;
`; `;
const HighlightedText = styled(Text)`
position: relative;
color: ${s("textSecondary")};
font-size: 14px;
padding: 0 8px;
margin: 4px 0;
display: inline-block;
${truncateMultiline(3)}
&:after {
content: "";
width: 2px;
position: absolute;
left: 0;
top: 2px;
bottom: 2px;
background: ${s("commentMarkBackground")};
border-radius: 2px;
}
`;
const Menu = styled(CommentMenu)<{ dir?: "rtl" | "ltr" }>` const Menu = styled(CommentMenu)<{ dir?: "rtl" | "ltr" }>`
position: absolute; position: absolute;
left: ${(props) => (props.dir !== "rtl" ? "auto" : "4px")}; left: ${(props) => (props.dir !== "rtl" ? "auto" : "4px")};

View File

@@ -42,7 +42,6 @@ function Comments() {
.threadsInDocument(document.id) .threadsInDocument(document.id)
.filter((thread) => !thread.isNew || thread.createdById === user.id); .filter((thread) => !thread.isNew || thread.createdById === user.id);
const hasComments = threads.length > 0; const hasComments = threads.length > 0;
const hasMultipleComments = comments.inDocument(document.id).length > 1;
return ( return (
<Sidebar <Sidebar
@@ -52,7 +51,6 @@ function Comments() {
> >
<Scrollable <Scrollable
id="comments" id="comments"
overflow={hasMultipleComments ? undefined : "initial"}
bottomShadow={!focusedComment} bottomShadow={!focusedComment}
hiddenScrollbars hiddenScrollbars
topShadow topShadow

View File

@@ -0,0 +1,29 @@
import styled from "styled-components";
import { s } from "@shared/styles";
import Text from "~/components/Text";
import { truncateMultiline } from "~/styles";
/**
* Highlighted text associated with a comment.
*/
export const HighlightedText = styled(Text)`
position: relative;
color: ${s("textSecondary")};
font-size: 14px;
padding: 0 8px;
margin: 4px 0;
display: inline-block;
${truncateMultiline(3)}
&:after {
content: "";
width: 2px;
position: absolute;
left: 0;
top: 2px;
bottom: 2px;
background: ${s("commentMarkBackground")};
border-radius: 2px;
}
`;