Commit a9ee261e authored by Karen Konou's avatar Karen Konou

[Doc annotation] Highlight changed terms immediately

parent 71928b67
...@@ -13,6 +13,7 @@ module Gargantext.Components.Annotation.Field where ...@@ -13,6 +13,7 @@ module Gargantext.Components.Annotation.Field where
import Gargantext.Prelude import Gargantext.Prelude
import DOM.Simple.Event as DE
import Data.Array as A import Data.Array as A
import Data.List (List(..), (:)) import Data.List (List(..), (:))
import Data.Map (Map) import Data.Map (Map)
...@@ -20,7 +21,6 @@ import Data.Maybe (Maybe(..), maybe) ...@@ -20,7 +21,6 @@ import Data.Maybe (Maybe(..), maybe)
import Data.String.Common (joinWith) import Data.String.Common (joinWith)
import Data.Tuple (Tuple(..), snd) import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Event as DE
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Annotation.Menu (annotationMenu, AnnotationMenu) import Gargantext.Components.Annotation.Menu (annotationMenu, AnnotationMenu)
import Gargantext.Components.Annotation.Types (MenuType(..), ModeType(..), termClass) import Gargantext.Components.Annotation.Types (MenuType(..), ModeType(..), termClass)
...@@ -29,6 +29,7 @@ import Gargantext.Core.NgramsTable.Types (HighlightElement, NgramsRepoElement(.. ...@@ -29,6 +29,7 @@ import Gargantext.Core.NgramsTable.Types (HighlightElement, NgramsRepoElement(..
import Gargantext.Types (CTabNgramType(..), TermList) import Gargantext.Types (CTabNgramType(..), TermList)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Selection as Sel import Gargantext.Utils.Selection as Sel
import Gargantext.Utils.Toestand as T2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Reactix.SyntheticEvent as E import Reactix.SyntheticEvent as E
...@@ -59,14 +60,16 @@ annotatedFieldCpt = here.component "annotatedField" cpt where ...@@ -59,14 +60,16 @@ annotatedFieldCpt = here.component "annotatedField" cpt where
cpt props _ = do cpt props _ = do
menuRef <- R.useRef (Nothing :: Maybe (Record AnnotationMenu)) menuRef <- R.useRef (Nothing :: Maybe (Record AnnotationMenu))
redrawMenu <- T.useBox false redrawMenu <- T.useBox false
reload <- T.useBox T2.newReload
pure $ annotatedFieldInner (Record.merge { menuRef, redrawMenu } props) pure $ annotatedFieldInner (Record.merge { menuRef, redrawMenu, reload } props)
----------------------------------------------------------------- -----------------------------------------------------------------
type InnerProps = type InnerProps =
( menuRef :: R.Ref (Maybe (Record AnnotationMenu)) ( menuRef :: R.Ref (Maybe (Record AnnotationMenu))
, redrawMenu :: T.Box Boolean , redrawMenu :: T.Box Boolean
, reload :: T2.ReloadS
| Props | Props
) )
...@@ -81,6 +84,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where ...@@ -81,6 +84,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
, text: fieldText , text: fieldText
, mode , mode
, cache , cache
, reload
} _ = do } _ = do
-- | States -- | States
-- | -- |
...@@ -94,7 +98,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where ...@@ -94,7 +98,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
wrap :: Tuple String (List (Tuple NgramsTerm TermList)) -> Record RunProps wrap :: Tuple String (List (Tuple NgramsTerm TermList)) -> Record RunProps
wrap (text /\ list) wrap (text /\ list)
= { list = { list
, onSelect: onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList } , onSelect: onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList, reload}
, text , text
} }
...@@ -126,7 +130,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where ...@@ -126,7 +130,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
annotateRun annotateRun
{ list: mempty { list: mempty
, text: t , text: t
, onSelect: onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList } , onSelect: onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList, reload }
} }
] ]
...@@ -149,12 +153,13 @@ onAnnotationSelect :: forall e. ...@@ -149,12 +153,13 @@ onAnnotationSelect :: forall e.
, ngrams :: NgramsTable , ngrams :: NgramsTable
, redrawMenu :: T.Box Boolean , redrawMenu :: T.Box Boolean
, setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit , setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit
, reload :: T2.ReloadS
} }
-> Maybe (Tuple NgramsTerm TermList) -> Maybe (Tuple NgramsTerm TermList)
-> E.SyntheticEvent e -> E.SyntheticEvent e
-> Effect Unit -> Effect Unit
onAnnotationSelect onAnnotationSelect
{ menuRef, ngrams, redrawMenu, setTermList } { menuRef, ngrams, redrawMenu, setTermList, reload}
Nothing Nothing
event event
= do = do
...@@ -170,11 +175,12 @@ onAnnotationSelect ...@@ -170,11 +175,12 @@ onAnnotationSelect
, menuType: NewNgram , menuType: NewNgram
, ngram: sel' -- normNgram CTabTerms sel' , ngram: sel' -- normNgram CTabTerms sel'
, redrawMenu , redrawMenu
, setTermList } , setTermList
, reload }
Nothing -> hideMenu { menuRef, redrawMenu } Nothing -> hideMenu { menuRef, redrawMenu }
onAnnotationSelect onAnnotationSelect
{ menuRef, redrawMenu, setTermList } { menuRef, redrawMenu, setTermList, reload }
(Just (Tuple ngram list)) (Just (Tuple ngram list))
event event
= showMenu = showMenu
...@@ -185,6 +191,7 @@ onAnnotationSelect ...@@ -185,6 +191,7 @@ onAnnotationSelect
, ngram , ngram
, redrawMenu , redrawMenu
, setTermList , setTermList
, reload
} }
-- showMenu :: forall p e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e | p } -> Effect Unit -- showMenu :: forall p e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e | p } -> Effect Unit
...@@ -197,10 +204,11 @@ showMenu :: forall e. ...@@ -197,10 +204,11 @@ showMenu :: forall e.
, ngram :: NgramsTerm , ngram :: NgramsTerm
, redrawMenu :: T.Box Boolean , redrawMenu :: T.Box Boolean
, setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit , setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit
, reload :: T2.ReloadS
} }
-> Effect Unit -> Effect Unit
showMenu showMenu
{ event, getList, menuRef, menuType, ngram, redrawMenu, setTermList } { event, getList, menuRef, menuType, ngram, redrawMenu, setTermList, reload }
= do = do
let x = E.clientX event let x = E.clientX event
y = E.clientY event y = E.clientY event
...@@ -210,6 +218,7 @@ showMenu ...@@ -210,6 +218,7 @@ showMenu
setList t = do setList t = do
setTermList ngram list t setTermList ngram list t
hideMenu { menuRef, redrawMenu } hideMenu { menuRef, redrawMenu }
T2.reload reload
E.preventDefault event E.preventDefault event
--range <- Sel.getRange sel 0 --range <- Sel.getRange sel 0
--here.log2 "selection range" $ Sel.rangeToTuple range --here.log2 "selection range" $ Sel.rangeToTuple range
......
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