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