Skip to content

Commit a80fd2e

Browse files
committed
♻️(frontend) replace default comment toolbar button
Replace the default comment toolbar button with a custom one to follow the design system.
1 parent 384ba0a commit a80fd2e

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-comments.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test.describe('Doc Comments', () => {
3636
// We add a comment with the first user
3737
const editor = await writeInEditor({ page, text: 'Hello World' });
3838
await editor.getByText('Hello').selectText();
39-
await page.getByRole('button', { name: 'Add comment' }).click();
39+
await page.getByRole('button', { name: 'Comment' }).click();
4040

4141
const thread = page.locator('.bn-thread');
4242
await thread.getByRole('paragraph').first().fill('This is a comment');
@@ -119,7 +119,7 @@ test.describe('Doc Comments', () => {
119119
const editor = page.locator('.ProseMirror');
120120
await editor.locator('.bn-block-outer').last().fill('Hello World');
121121
await editor.getByText('Hello').selectText();
122-
await page.getByRole('button', { name: 'Add comment' }).click();
122+
await page.getByRole('button', { name: 'Comment' }).click();
123123

124124
const thread = page.locator('.bn-thread');
125125
await thread.getByRole('paragraph').first().fill('This is a comment');

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/BlockNoteToolbar.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
1010

1111
import { useConfig } from '@/core/config/api';
1212

13+
import { CommentToolbarButton } from '../comments/CommentToolbarButton';
1314
import { getCalloutFormattingToolbarItems } from '../custom-blocks';
1415

1516
import { AIGroupButton } from './AIButton';
@@ -25,17 +26,21 @@ export const BlockNoteToolbar = () => {
2526
const { data: conf } = useConfig();
2627

2728
const toolbarItems = useMemo(() => {
28-
const toolbarItems = getFormattingToolbarItems([
29+
let toolbarItems = getFormattingToolbarItems([
2930
...blockTypeSelectItems(dict),
3031
getCalloutFormattingToolbarItems(t),
3132
]);
33+
34+
// Find the index of the file download button
3235
const fileDownloadButtonIndex = toolbarItems.findIndex(
3336
(item) =>
3437
typeof item === 'object' &&
3538
item !== null &&
3639
'key' in item &&
3740
(item as { key: string }).key === 'fileDownloadButton',
3841
);
42+
43+
// Replace the default file download button with our custom FileDownloadButton
3944
if (fileDownloadButtonIndex !== -1) {
4045
toolbarItems.splice(
4146
fileDownloadButtonIndex,
@@ -50,12 +55,22 @@ export const BlockNoteToolbar = () => {
5055
);
5156
}
5257

58+
// Remove default Comment button
59+
toolbarItems = toolbarItems.filter((item) => {
60+
if (typeof item === 'object' && item !== null && 'key' in item) {
61+
return item.key !== 'addCommentButton';
62+
}
63+
return true;
64+
});
65+
5366
return toolbarItems;
5467
}, [dict, t]);
5568

5669
const formattingToolbar = useCallback(() => {
5770
return (
5871
<FormattingToolbar>
72+
<CommentToolbarButton />
73+
5974
{toolbarItems}
6075

6176
{/* Extra button to do some AI powered actions */}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { useBlockNoteEditor, useComponentsContext } from '@blocknote/react';
2+
import { useTranslation } from 'react-i18next';
3+
import { css } from 'styled-components';
4+
5+
import { Box, Icon } from '@/components';
6+
import { useCunninghamTheme } from '@/cunningham';
7+
import { useDocStore } from '@/features/docs/doc-management';
8+
9+
import {
10+
DocsBlockSchema,
11+
DocsInlineContentSchema,
12+
DocsStyleSchema,
13+
} from '../../types';
14+
15+
export const CommentToolbarButton = () => {
16+
const Components = useComponentsContext();
17+
const { currentDoc } = useDocStore();
18+
const { t } = useTranslation();
19+
const { spacingsTokens, colorsTokens } = useCunninghamTheme();
20+
const editor = useBlockNoteEditor<
21+
DocsBlockSchema,
22+
DocsInlineContentSchema,
23+
DocsStyleSchema
24+
>();
25+
26+
const hasActiveUnresolvedThread = editor._tiptapEditor.isActive('comment', {
27+
orphan: false,
28+
});
29+
30+
if (
31+
!editor.isEditable ||
32+
!Components ||
33+
!currentDoc?.abilities.comment ||
34+
hasActiveUnresolvedThread
35+
) {
36+
return null;
37+
}
38+
39+
return (
40+
<Box $direction="row" className="--docs--comment-toolbar-button">
41+
<Components.Generic.Toolbar.Button
42+
className="bn-button"
43+
onClick={() => {
44+
editor.comments?.startPendingComment();
45+
}}
46+
isDisabled={hasActiveUnresolvedThread}
47+
>
48+
<Box
49+
$direction="row"
50+
$align="center"
51+
$gap={spacingsTokens['xs']}
52+
$padding={{ right: '2xs' }}
53+
>
54+
<Icon
55+
iconName="comment"
56+
className="--docs--icon-bg"
57+
$theme="greyscale"
58+
$variation="600"
59+
$padding="0.15rem"
60+
$size="16px"
61+
$color={
62+
hasActiveUnresolvedThread
63+
? `${colorsTokens['greyscale-600']}77`
64+
: colorsTokens['greyscale-600']
65+
}
66+
/>
67+
{t('Comment')}
68+
</Box>
69+
</Components.Generic.Toolbar.Button>
70+
<Box
71+
$background={colorsTokens['greyscale-100']}
72+
$width="1px"
73+
$height="70%"
74+
$margin={{ left: '2px' }}
75+
$css={css`
76+
align-self: center;
77+
`}
78+
/>
79+
</Box>
80+
);
81+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './CommentToolbarButton';
12
export * from './styles';
23
export * from './useComments';

0 commit comments

Comments
 (0)