Commit 9e975cf6 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[tree] popover close works now

parent 66ad76db
...@@ -3,14 +3,16 @@ module Gargantext.Components.Forest.Tree.Node.Box where ...@@ -3,14 +3,16 @@ module Gargantext.Components.Forest.Tree.Node.Box where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (null) import Data.Nullable (null, toMaybe)
import Data.Tuple (Tuple(..), fst, snd) import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple as DOM
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, launchAff) import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..))
import React.SyntheticEvent as E import React.SyntheticEvent as E
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -69,9 +71,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el ...@@ -69,9 +71,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
-- only 1 popup at a time is allowed to be opened -- only 1 popup at a time is allowed to be opened
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile) droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
isDragOver <- R.useState' false isDragOver <- R.useState' false
popoverOpen <- R.useState' false
popperRef <- R.useRef null popoverRef <- R.useRef null
pure $ H.span (dropProps droppedFile isDragOver) $ pure $ H.span (dropProps droppedFile isDragOver) $
[ folderIcon nodeType folderOpen [ folderIcon nodeType folderOpen
...@@ -83,12 +84,15 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el ...@@ -83,12 +84,15 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
} }
[ nodeText { isSelected: (mCorpusId mCurrentRoute) == (Just id) [ nodeText { isSelected: (mCorpusId mCurrentRoute) == (Just id)
, name: name' props} ] , name: name' props} ]
, Popover.popover { open: fst popoverOpen , if showBox then
, onClose: \_ -> snd popoverOpen $ const false Popover.popover { open: false
, onOpen: \_ -> snd popoverOpen $ const true } [ , onClose: \_ -> pure unit
popOverIcon true , onOpen: \_ -> pure unit
, mNodePopupView props showBox , ref: popoverRef } [
popOverIcon
, mNodePopupView props (onPopoverClose popoverRef)
] ]
else H.div {} []
, fileTypeView {dispatch, droppedFile, id, isDragOver, nodeType} , fileTypeView {dispatch, droppedFile, id, isDragOver, nodeType}
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t , H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, corpusId: id , corpusId: id
...@@ -97,6 +101,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el ...@@ -97,6 +101,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
] ]
where where
SettingsBox {show: showBox} = settingsBox nodeType SettingsBox {show: showBox} = settingsBox nodeType
onPopoverClose popoverRef _ = do
Popover.setOpen popoverRef false
name' {name, nodeType} = if nodeType == GT.NodeUser then show session else name name' {name, nodeType} = if nodeType == GT.NodeUser then show session else name
...@@ -104,18 +110,17 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el ...@@ -104,18 +110,17 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
H.a {onClick: R2.effToggler folderOpen'} H.a {onClick: R2.effToggler folderOpen'}
[ H.i {className: GT.fldr nodeType open} [] ] [ H.i {className: GT.fldr nodeType open} [] ]
popOverIcon false = H.div {} [] popOverIcon =
popOverIcon true =
H.a { className: "glyphicon glyphicon-cog" H.a { className: "glyphicon glyphicon-cog"
, id: "rename-leaf" , id: "rename-leaf"
} [] } []
mNodePopupView _ false = H.div {} [] mNodePopupView props@{asyncTasks, id, nodeType} onPopoverClose =
mNodePopupView props@{asyncTasks, id, nodeType} true =
nodePopupView { id nodePopupView { id
, dispatch , dispatch
, name: name' props , name: name' props
, nodeType , nodeType
, onPopoverClose
, session , session
} }
...@@ -190,6 +195,7 @@ type NodePopupProps = ...@@ -190,6 +195,7 @@ type NodePopupProps =
( id :: ID ( id :: ID
, name :: Name , name :: Name
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, onPopoverClose :: DOM.Element -> Effect Unit
| CommonProps | CommonProps
) )
...@@ -260,6 +266,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -260,6 +266,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, H.div {className: "col-md-1"} , H.div {className: "col-md-1"}
[ H.a { "type" : "button" [ H.a { "type" : "button"
, className: glyphicon "remove-circle" , className: glyphicon "remove-circle"
, on: { click: \e -> p.onPopoverClose $ R2.unsafeEventTarget e }
, title : "Close"} [] , title : "Close"} []
] ]
] ]
...@@ -274,8 +281,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -274,8 +281,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
[ H.a { className: glyphicon "pencil" [ H.a { className: glyphicon "pencil"
, id : "rename1" , id : "rename1"
, title : "Rename" , title : "Rename"
, onClick : mkEffectFn1 , on: { click: \_ -> setRenameBoxOpen $ const true }
$ \_ -> setRenameBoxOpen $ const true
} }
[] []
] ]
......
...@@ -7,3 +7,6 @@ if (typeof window !== 'undefined') { ...@@ -7,3 +7,6 @@ if (typeof window !== 'undefined') {
} }
exports.popoverCpt = popover; exports.popoverCpt = popover;
exports._setState = function(el, open) {
el.setState({open: open});
}
module Gargantext.Utils.Popover where module Gargantext.Utils.Popover where
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, toMaybe)
import DOM.Simple as DOM
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)
import FFI.Simple ((..), (...))
import Reactix as R import Reactix as R
import Gargantext.Prelude import Gargantext.Prelude
type PopoverRef = R.Ref (Nullable DOM.Element)
type Props = type Props =
( (
open :: Boolean open :: Boolean
, onClose :: Unit -> Effect Unit , onClose :: Unit -> Effect Unit
, onOpen :: Unit -> Effect Unit , onOpen :: Unit -> Effect Unit
, ref :: PopoverRef
) )
foreign import popoverCpt :: R.Component Props foreign import popoverCpt :: R.Component Props
popover :: Record Props -> Array R.Element -> R.Element popover :: Record Props -> Array R.Element -> R.Element
popover = R.rawCreateElement popoverCpt popover = R.rawCreateElement popoverCpt
foreign import _setState :: EffectFn2 DOM.Element Boolean Unit
setState :: DOM.Element -> Boolean -> Effect Unit
setState = runEffectFn2 _setState
setOpen :: PopoverRef -> Boolean -> Effect Unit
setOpen ref val =
case toMaybe $ R.readRef ref of
Nothing -> pure unit
Just p -> do
setState p val
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