From c65868921d5587af43687b814020d4ea03b1cfd2 Mon Sep 17 00:00:00 2001 From: Kevin Tun Date: Fri, 14 Feb 2025 13:09:10 -0600 Subject: [PATCH] feat(editor): conditionally render toolbar based on props and remove unused code The toolbar is now conditionally rendered based on the `toolbar` and `editable` props. The `fp-ts` library is used to handle the nullable `toolbar` prop and the boolean `editable` prop. Unnecessary commented-out code and styles were removed to improve code readability. --- packages/editor/src/Editor.tsx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/editor/src/Editor.tsx b/packages/editor/src/Editor.tsx index 6efc0179d..8990c1258 100644 --- a/packages/editor/src/Editor.tsx +++ b/packages/editor/src/Editor.tsx @@ -11,6 +11,7 @@ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin" import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary" import { Grid } from "@material-ui/core" import { pipe } from "fp-ts/function" +import { match as Bmatch } from "fp-ts/boolean" import { getOrElse as OgetOrElse, fromNullable as OfromNullable, @@ -53,7 +54,6 @@ const Editor = ({ OgetOrElse(() => initialStateString as InitialEditorStateType), ) const placeholderClasses = useEditorPlaceholderStyles() - // const persistencePluginStyles = usePersistencePluginStyles() const editorAreaClasses = useEditorAreaStyles({ editable }) return ( @@ -71,20 +71,22 @@ const Editor = ({ - {/* {content?.storageKey ? ( - - ) : ( - <> - )} */} - {/* */} - {toolbar ? {toolbar} : <>} - {editable ? ( - - - - ) : ( - <> + {pipe( + toolbar, + OfromNullable, + Omap((tb) => {tb}), + )} + {pipe( + editable, + Bmatch( + () => <>, + () => ( + + + + ), + ), )}