Skip to content

Commit

Permalink
fix: Formatting toolbar clipped on first comment in sidebar, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Apr 25, 2024
1 parent cffd0be commit bf848f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
17 changes: 14 additions & 3 deletions app/components/Scrollable.tsx
Expand Up @@ -10,11 +10,20 @@ type Props = React.HTMLAttributes<HTMLDivElement> & {
bottomShadow?: boolean;
hiddenScrollbars?: boolean;
flex?: boolean;
overflow?: string;
children: React.ReactNode;
};

function Scrollable(
{ shadow, topShadow, bottomShadow, hiddenScrollbars, flex, ...rest }: Props,
{
shadow,
topShadow,
bottomShadow,
hiddenScrollbars,
flex,
overflow,
...rest
}: Props,
ref: React.RefObject<HTMLDivElement>
) {
const fallbackRef = React.useRef<HTMLDivElement>();
Expand Down Expand Up @@ -60,6 +69,7 @@ function Scrollable(
$hiddenScrollbars={hiddenScrollbars}
$topShadowVisible={topShadowVisible}
$bottomShadowVisible={bottomShadowVisible}
$overflow={overflow}
{...rest}
/>
);
Expand All @@ -70,12 +80,13 @@ const Wrapper = styled.div<{
$topShadowVisible?: boolean;
$bottomShadowVisible?: boolean;
$hiddenScrollbars?: boolean;
$overflow?: string;
}>`
display: ${(props) => (props.$flex ? "flex" : "block")};
flex-direction: column;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
overflow-y: ${(props) => (props.$overflow ? props.$overflow : "auto")};
overflow-x: ${(props) => (props.$overflow ? props.$overflow : "hidden")};
overscroll-behavior: none;
-webkit-overflow-scrolling: touch;
box-shadow: ${(props) => {
Expand Down
4 changes: 3 additions & 1 deletion app/scenes/Document/components/Comments.tsx
Expand Up @@ -42,6 +42,7 @@ function Comments() {
.threadsInDocument(document.id)
.filter((thread) => !thread.isNew || thread.createdById === user.id);
const hasComments = threads.length > 0;
const hasMultipleComments = comments.inDocument(document.id).length > 1;

return (
<Sidebar
Expand All @@ -50,8 +51,9 @@ function Comments() {
scrollable={false}
>
<Scrollable
bottomShadow={!focusedComment}
id="comments"
overflow={hasMultipleComments ? undefined : "initial"}
bottomShadow={!focusedComment}
hiddenScrollbars
topShadow
>
Expand Down
10 changes: 10 additions & 0 deletions app/stores/CommentsStore.ts
Expand Up @@ -9,6 +9,16 @@ export default class CommentsStore extends Store<Comment> {
super(rootStore, Comment);
}

/**
* Returns a list of comments in a document.
*
* @param documentId ID of the document to get comments for
* @returns Array of comments
*/
inDocument(documentId: string): Comment[] {
return this.filter((comment: Comment) => comment.documentId === documentId);
}

/**
* Returns a list of comments in a document that are not replies to other
* comments.
Expand Down

0 comments on commit bf848f3

Please sign in to comment.