Commit 9702974a authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Markdown] some more work on the editor

parent 900956af
module Gargantext.Components.MarkdownEditor where module Gargantext.Components.MarkdownEditor where
import Data.Either (either, Either(..)) import Data.Either (either, Either(..))
import Prelude (($), (>>>), identity, pure) import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null, toMaybe)
import FFI.Simple ((.=))
import Prelude (($), (>>>), bind, discard, identity, pure, unit)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Text.Markdown.SlamDown.Parser (parseMd) import Text.Markdown.SlamDown.Parser (parseMd)
...@@ -28,6 +31,15 @@ markdownEditor p = R.createElement markdownEditorCpt p [] ...@@ -28,6 +31,15 @@ markdownEditor p = R.createElement markdownEditorCpt p []
markdownEditorCpt :: R.Component Props markdownEditorCpt :: R.Component Props
markdownEditorCpt = R.hooksComponent "G.C.MarkdownEditor" cpt markdownEditorCpt = R.hooksComponent "G.C.MarkdownEditor" cpt
where where
cpt {md, nodeId} _ = cpt {md, nodeId} _ = do
pure $ ref <- R.useRef null
H.div {} [ H.text $ compileMd md ]
R.useEffect1' md $ do
let mDiv = toMaybe $ R.readRef ref
case mDiv of
Nothing -> pure unit
Just d -> do
_ <- pure $ ("innerHTML" .= d) $ compileMd md
pure unit
pure $ H.div { ref } []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment