Commit af918879 authored by James Laver's avatar James Laver Committed by Alexandre Delanoë

upgrade to use reactix 0.1.0

parent 22a391de
...@@ -20,6 +20,7 @@ import Data.Tuple ( Tuple(..) ) ...@@ -20,6 +20,7 @@ import Data.Tuple ( Tuple(..) )
import Effect ( Effect ) import Effect ( Effect )
import Reactix as R import Reactix as R
import Reactix.DOM.Raw as RDOM import Reactix.DOM.Raw as RDOM
import Reactix.SyntheticEvent as E
import Gargantext.Types ( TermList(..) ) import Gargantext.Types ( TermList(..) )
import Gargantext.Components.Annotation.Utils ( termClass ) import Gargantext.Components.Annotation.Utils ( termClass )
...@@ -37,13 +38,13 @@ defaultProps :: Record Props ...@@ -37,13 +38,13 @@ defaultProps :: Record Props
defaultProps = { ngrams: NgramsTable Map.empty, text: Nothing } defaultProps = { ngrams: NgramsTable Map.empty, text: Nothing }
annotatedField :: Record Props -> R.Element annotatedField :: Record Props -> R.Element
annotatedField = R.createLeaf annotatedFieldComponent annotatedField p = R.createElement annotatedFieldComponent p []
annotatedFieldComponent :: R.Component Props annotatedFieldComponent :: R.Component Props
annotatedFieldComponent = R.pureLeaf "AnnotatedField" cpt annotatedFieldComponent = R.staticComponent "AnnotatedField" cpt
where where
runs props = annotateRun <$> compile props runs props = annotateRun <$> compile props
cpt props = cpt props _ =
RDOM.div { className: "annotated-field-wrapper" } RDOM.div { className: "annotated-field-wrapper" }
[ annotationMenu { termList: Nothing } [ annotationMenu { termList: Nothing }
, RDOM.div { className: "annotated-field-runs" } (annotateRun <$> compile props) ] , RDOM.div { className: "annotated-field-runs" } (annotateRun <$> compile props) ]
...@@ -51,11 +52,11 @@ annotatedFieldComponent = R.pureLeaf "AnnotatedField" cpt ...@@ -51,11 +52,11 @@ annotatedFieldComponent = R.pureLeaf "AnnotatedField" cpt
type RunProps = ( list :: Maybe TermList, text :: String ) type RunProps = ( list :: Maybe TermList, text :: String )
annotateRun :: Run -> R.Element annotateRun :: Run -> R.Element
annotateRun (Tuple text list) = R.createLeaf annotatedRunComponent { text, list } annotateRun (Tuple text list) = R.createElement annotatedRunComponent { text, list } []
annotatedRunComponent :: R.Component RunProps annotatedRunComponent :: R.Component RunProps
annotatedRunComponent = R.pureLeaf "AnnotatedRun" cpt annotatedRunComponent = R.staticComponent "AnnotatedRun" cpt
where cpt { text, list } = maybe (unstyled text) (styled text) list where cpt { text, list } _ = maybe (unstyled text) (styled text) list
styled text list = RDOM.span { className: className list } [ RDOM.text text ] styled text list = RDOM.span { className: className list } [ RDOM.text text ]
unstyled text = RDOM.span {} [ RDOM.text text ] unstyled text = RDOM.span {} [ RDOM.text text ]
className list = "annotation-run " <> termClass list className list = "annotation-run " <> termClass list
...@@ -65,16 +66,16 @@ compile props = runs props.text ...@@ -65,16 +66,16 @@ compile props = runs props.text
where runs (Just text) = highlightNgrams props.ngrams text where runs (Just text) = highlightNgrams props.ngrams text
runs _ = [] runs _ = []
maybeShowMenu :: SyntheticEvent -> NgramsTable -> (Maybe TermList -> Effect Unit) -> Effect Unit maybeShowMenu :: E.MouseEvent -> NgramsTable -> (Maybe TermList -> Effect Unit) -> Effect Unit
maybeShowMenu e n a = Sel.getSelection >>= traverse_ (a <<< findNgram n <<< Sel.toString) maybeShowMenu e n a = Sel.getSelection >>= traverse_ (a <<< findNgram n <<< Sel.toString)
showMenu -- showMenu
findNgram :: NgramsTable -> String -> Maybe TermList findNgram :: NgramsTable -> String -> Maybe TermList
findNgram _ _ = Nothing findNgram _ _ = Nothing
-- contextMenuHandler :: (Action -> Effect Unit) -> SyntheticMouseEvent -> Effect Unit -- contextMenuHandler :: (Action -> Effect Unit) -> MouseEvent -> Effect Unit
-- contextMenuHandler d e = -- contextMenuHandler d e =
-- do sel <- getSelection -- do sel <- getSelection
-- case toString <$> sel of -- case toString <$> sel of
......
...@@ -22,14 +22,13 @@ type Props = ( termList :: Maybe TermList ) ...@@ -22,14 +22,13 @@ type Props = ( termList :: Maybe TermList )
-- | An Annotation Menu is parameterised by a Maybe Termlist of the -- | An Annotation Menu is parameterised by a Maybe Termlist of the
-- | TermList the currently selected text belongs to -- | TermList the currently selected text belongs to
annotationMenu :: Record Props -> R.Element annotationMenu :: Record Props -> R.Element
annotationMenu = R.createLeaf annotationMenuCpt annotationMenu p = R.createElement annotationMenuCpt p []
annotationMenuCpt :: R.Component Props annotationMenuCpt :: R.Component Props
annotationMenuCpt = R.hooksLeaf "Annotation.Menu" cpt annotationMenuCpt = R.hooksComponent "Annotation.Menu" cpt
where where
cpt :: forall m. R'.HooksLeaf m Props cpt { termList } _ = pure $
cpt { termList } = pure $ RDOM.div { className: "annotation-menu" } [ CM.contextMenu $ children termList ]
R'.div { className: "annotation-menu" } [ CM.contextMenu $ children termList ]
children l = A.mapMaybe (\l' -> addToList l' l) [ GraphTerm, CandidateTerm, StopTerm ] children l = A.mapMaybe (\l' -> addToList l' l) [ GraphTerm, CandidateTerm, StopTerm ]
-- | Given the TermList to render the item for and the Maybe TermList the item may belong to, possibly render the menuItem -- | Given the TermList to render the item for and the Maybe TermList the item may belong to, possibly render the menuItem
......
...@@ -10,23 +10,21 @@ import Reactix.DOM.Raw as RDOM ...@@ -10,23 +10,21 @@ import Reactix.DOM.Raw as RDOM
import Gargantext.Utils.Reactix as R' import Gargantext.Utils.Reactix as R'
contextMenu :: Array R.Element -> R.Element contextMenu :: Array R.Element -> R.Element
contextMenu = R.createTree contextMenuCpt {} contextMenu = R.createElement contextMenuCpt {}
contextMenuCpt :: R.Component (R'.WithChildren ()) contextMenuCpt :: R.Component ()
contextMenuCpt = R.hooksTree "ContextMenu" cpt contextMenuCpt = R.hooksComponent "ContextMenu" cpt
where where
cpt :: forall m. R'.HooksTree m ()
cpt _props children = pure $ cpt _props children = pure $
R'.nav { className: "context-menu" } R'.nav { className: "context-menu" }
[ R'.ul { className: "context-menu-items" } children ] [ R'.ul { className: "context-menu-items" } children ]
contextMenuItem :: Array R.Element -> R.Element contextMenuItem :: Array R.Element -> R.Element
contextMenuItem = R.createTree contextMenuItemCpt {} contextMenuItem = R.createElement contextMenuItemCpt {}
contextMenuItemCpt :: R.Component (R'.WithChildren ()) contextMenuItemCpt :: R.Component ()
contextMenuItemCpt = R.hooksTree "ContextMenuItem" cpt contextMenuItemCpt = R.hooksComponent "ContextMenuItem" cpt
where where
cpt :: forall m. R'.HooksTree m ()
cpt _props children = pure $ R'.li { className: "context-menu-item" } children cpt _props children = pure $ R'.li { className: "context-menu-item" } children
......
module Gargantext.Utils.Reactix module Gargantext.Utils.Reactix
( WithChildren, HooksTree, HooksLeaf, buff, scuff, nav, ul, li, a, div ) ( buff, scuff, nav, ul, li, a, div )
where where
import React ( ReactElement ) import React ( ReactElement )
import Reactix as R import Reactix as R
import Unsafe.Coerce ( unsafeCoerce ) import Unsafe.Coerce ( unsafeCoerce )
-- | A convenience for adding `children` to a list of props
type WithChildren p = ( children :: R.Children | p )
type HooksTree m p = R.MonadHooks m => Record p -> Array R.Element -> m R.Element
type HooksLeaf m p = R.MonadHooks m => Record p -> m R.Element
-- | Turns a ReactElement into a Reactix Element -- | Turns a ReactElement into a Reactix Element
-- | buff (v.) to polish -- | buff (v.) to polish
buff :: ReactElement -> R.Element buff :: ReactElement -> R.Element
...@@ -22,18 +16,15 @@ buff = unsafeCoerce ...@@ -22,18 +16,15 @@ buff = unsafeCoerce
scuff :: R.Element -> ReactElement scuff :: R.Element -> ReactElement
scuff = unsafeCoerce scuff = unsafeCoerce
div :: forall r. Record r -> Array R.Element -> R.Element
div = R.createDOMElement "div"
nav :: forall r. Record r -> Array R.Element -> R.Element nav :: forall r. Record r -> Array R.Element -> R.Element
nav = R.createDOMElement "nav" nav = R.createElement "nav"
ul :: forall r. Record r -> Array R.Element -> R.Element ul :: forall r. Record r -> Array R.Element -> R.Element
ul = R.createDOMElement "ul" ul = R.createElement "ul"
li :: forall r. Record r -> Array R.Element -> R.Element li :: forall r. Record r -> Array R.Element -> R.Element
li = R.createDOMElement "li" li = R.createElement "li"
a :: forall r. Record r -> Array R.Element -> R.Element a :: forall r. Record r -> Array R.Element -> R.Element
a = R.createDOMElement "a" a = R.createElement "a"
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