Commit 8096c7db authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT|DESIGN] refactoring Node Box submit button (next)

parent 58f378f4
......@@ -26,14 +26,14 @@ data Action = AddNode String GT.NodeType
instance showShow :: Show Action where
show DeleteNode = "DeleteNode"
show DeleteNode = "DeleteNode"
show RefreshTree = "RefreshTree"
show (ShareNode _) = "ShareNode"
show (UpdateNode _) = "UpdateNode"
show (RenameNode _) = "RenameNode"
show (SearchQuery _) = "SearchQuery"
show (AddNode _ _) = "AddNode"
show (UpdateNode _) = "UpdateNode"
show (RenameNode _) = "RenameNode"
show (SearchQuery _) = "SearchQuery"
show (UploadFile _ _ _ _)= "UploadFile"
show RefreshTree = "RefreshTree"
show (ShareNode _) = "ShareNode"
-----------------------------------------------------
-- TODO Delete with asyncTaskWithType
......
......@@ -9,6 +9,7 @@ import Effect.Aff (Aff, launchAff)
import Effect.Uncurried (mkEffectFn1)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node (SettingsBox(..), settingsBox)
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton)
import Gargantext.Types (NodeType(..), readNodeType)
import Gargantext.Utils.Reactix as R2
import Gargantext.Sessions (Session, post)
......@@ -62,11 +63,11 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
where
el = R.hooksComponent "AddNodeView" cpt
cpt {id, name} _ = do
nodeName <- R.useState' "Name"
nodeType' <- R.useState' $ fromMaybe NodeUser $ head nodeTypes
nodeName@(name' /\ _) <- R.useState' "Name"
nodeType'@(nt /\ _) <- R.useState' $ fromMaybe NodeUser $ head nodeTypes
pure $ H.div {}
[ panelBody readNodeType nodeName nodeType'
, panelFooter nodeName nodeType'
, submitButton (AddNode name' nt) dispatch -- panelFooter nodeName nodeType'
]
where
panelBody :: (String -> NodeType)
......@@ -116,23 +117,6 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
]
panelFooter :: R.State String -> R.State NodeType -> R.Element
panelFooter (name' /\ _) (nt /\ _) =
H.div { className: "panel-footer"}
[ H.div {} []
, H.div {className: "center"}
[ H.button {className: "btn btn-primary"
, type : "button"
, style : { width: "50%" }
, onClick: mkEffectFn1 $ \_ -> do
-- TODO
--setPopupOpen $ const Nothing
launchAff $ dispatch $ AddNode name' nt
} [H.text "Add"]
]
]
-- END Create Node
showConfig :: NodeType -> R.Element
......
......@@ -10,7 +10,7 @@ import Gargantext.Types as GT
import Gargantext.Types (ID)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, put)
import Gargantext.Components.Forest.Tree.Node.Tools.TextInputBox as Tools
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
------------------------------------------------------------------------
rename :: Session -> ID -> RenameValue -> Aff (Array ID)
......
......@@ -10,7 +10,7 @@ import Gargantext.Types as GT
import Gargantext.Types (ID)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, post)
import Gargantext.Components.Forest.Tree.Node.Tools.TextInputBox as Tools
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
------------------------------------------------------------------------
share :: Session -> ID -> ShareValue -> Aff (Array ID)
......
......@@ -31,6 +31,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Rename (textInputBox, renam
import Gargantext.Components.Forest.Tree.Node.Action.Share as Share
import Gargantext.Components.Forest.Tree.Node.Action.Upload (DroppedFile(..), uploadFileView, fileTypeView, uploadTermListView)
import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar, BarType(..))
import Gargantext.Components.Forest.Tree.Node.Tools
import Gargantext.Components.GraphExplorer.API as GraphAPI
import Gargantext.Components.Lang (allLangs, Lang(EN))
import Gargantext.Components.NgramsTable.API as NTAPI
......@@ -651,43 +652,8 @@ actionDelete _ dispatch = do
, "If yes, click again below."
]
)
, submitButton DeleteNode dispatch -- buttonDelete dispatch
, submitButton DeleteNode dispatch
]
where
buttonDelete :: (Action -> Aff Unit) -> R.Element
buttonDelete d =
H.div {className: "panel-footer"}
[ H.div {} []
, H.div { className: "center"}
[ H.button { className : "btn btn-primary glyphicon glyphicon-trash"
, type: "button"
, style : { width: "50%" }
, id: "delete"
, title: "Delete"
, on: {click: \_ -> launchAff $ d $ DeleteNode}
}
[ H.text "Delete!"]
]
]
type ButtonTitle = String
type ButtonIcon = String
submitButton :: Action -> (Action -> Aff Unit) -> R.Element
submitButton action dispatch =
H.div {className: "panel-footer"}
[ H.div {} []
, H.div { className: "center"}
[ H.button { className : "btn btn-primary fa fa-" <> icon action
, type: "button"
, style : { width: "50%" }
, id: S.toLower $ show action
, title: show action
, on: {click: \_ -> launchAff $ dispatch action}
}
[ H.text $ " " <> text action]
]
]
-- | Action : Upload
......
module Gargantext.Components.Forest.Tree.Node.Tools.TextInputBox where
module Gargantext.Components.Forest.Tree.Node.Tools where
import Data.String as S
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff)
import Effect.Uncurried (mkEffectFn1)
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Types (ID)
import Gargantext.Utils.Reactix as R2
import Prelude (Unit, bind, const, discard, pure, ($), (<<<), (<>))
import Gargantext.Prelude (Unit, bind, const, discard, identity, map, pure, show, unit, void, ($), (+), (<>), (==), (<<<))
import Reactix as R
import Reactix.DOM.HTML as H
......@@ -65,3 +66,22 @@ textInputBox p@{ boxName, isOpen: (false /\ _) } = R.createElement el p []
-- | END Rename Box
submitButton :: Action -> (Action -> Aff Unit) -> R.Element
submitButton action dispatch =
H.div {className: "panel-footer"}
[ H.div {} []
, H.div { className: "center"}
[ H.button { className : "btn btn-primary fa fa-" <> icon action
, type: "button"
, style : { width: "50%" }
, id: S.toLower $ show action
, title: show action
, on: {click: \_ -> launchAff $ dispatch action}
}
[ H.text $ " " <> text action]
]
]
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