🚸(frontend) do not show comments button on resources

The comments does not seems to work on
resources (images, pdf, ...), so we hide the button
when the selected block is not a text block.
This commit is contained in:
Anthony LC
2025-11-26 09:50:58 +01:00
parent 7dae3a3c02
commit 2864669dde
2 changed files with 72 additions and 6 deletions

View File

@@ -1,4 +1,9 @@
import { useBlockNoteEditor, useComponentsContext } from '@blocknote/react';
import {
useBlockNoteEditor,
useComponentsContext,
useSelectedBlocks,
} from '@blocknote/react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { css } from 'styled-components';
@@ -24,7 +29,18 @@ export const CommentToolbarButton = () => {
DocsStyleSchema
>();
if (!editor.isEditable || !Components || !currentDoc?.abilities.comment) {
const selectedBlocks = useSelectedBlocks(editor);
const show = useMemo(() => {
return !!selectedBlocks.find((block) => block.content !== undefined);
}, [selectedBlocks]);
if (
!show ||
!editor.isEditable ||
!Components ||
!currentDoc?.abilities.comment
) {
return null;
}
@@ -34,8 +50,10 @@ export const CommentToolbarButton = () => {
className="bn-button"
onClick={() => {
editor.comments?.startPendingComment();
editor.formattingToolbar.closeMenu();
}}
aria-haspopup="dialog"
data-test="comment-toolbar-button"
>
<Box
$direction="row"