From 00b223f648c6fe7018562018727d23105ab2b5c6 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Fri, 30 Aug 2024 14:55:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5(frontend)=20hide=20markdown=20butt?= =?UTF-8?q?on=20if=20not=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we are selected a block that is not a text block, we hide the markdown button. --- .../docs/doc-editor/components/BlockNoteToolbar.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx index 5f20e8e5..785f84c2 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx @@ -11,9 +11,10 @@ import { UnnestBlockButton, useBlockNoteEditor, useComponentsContext, + useSelectedBlocks, } from '@blocknote/react'; import { forEach, isArray } from 'lodash'; -import React from 'react'; +import React, { useMemo } from 'react'; export const BlockNoteToolbar = () => { return ( @@ -91,6 +92,7 @@ const recursiveContent = (content: Block[], base: string = '') => { export function MarkdownButton() { const editor = useBlockNoteEditor(); const Components = useComponentsContext(); + const selectedBlocks = useSelectedBlocks(editor); const handleConvertMarkdown = () => { const blocks = editor.getSelection()?.blocks; @@ -114,7 +116,11 @@ export function MarkdownButton() { }); }; - if (!Components) { + const show = useMemo(() => { + return !!selectedBlocks.find((block) => block.content !== undefined); + }, [selectedBlocks]); + + if (!show || !editor.isEditable || !Components) { return null; }