Commit ba53ab68 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[refactoring] some components refactoring, fixes to input with enter

parent e5a139f5
......@@ -86,7 +86,6 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
onEnter: \_ -> launchAff_ $ dispatch (AddNode name' nt')
, onValueChanged: \val -> setNodeName $ const val
, autoFocus: true
, autoSave: false
, className: "form-control"
, defaultValue: name'
, placeholder: name'
......
......@@ -55,8 +55,8 @@ linkNodeType (Just GT.Annuaire) = GT.Corpus
linkNodeType _ = GT.Error
linkNode :: Record SubTreeParamsIn -> R.Element
linkNode p = R.createElement linkNodeCpt p []
linkNode :: R2.Component SubTreeParamsIn
linkNode = R.createElement linkNodeCpt
linkNodeCpt :: R.Component SubTreeParamsIn
linkNodeCpt = R.hooksComponentWithModule thisModule "linkNode" cpt
......
......@@ -22,12 +22,12 @@ mergeNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
mergeNodeReq session fromId toId =
put_ session $ NodeAPI GT.Node (Just fromId) ("merge/" <> show toId)
mergeNode :: Record SubTreeParamsIn -> R.Element
mergeNode p = R.createElement mergeNodeCpt p []
where
mergeNodeCpt :: R.Component SubTreeParamsIn
mergeNodeCpt = R.hooksComponentWithModule thisModule "mergeNode" cpt
mergeNode :: R2.Component SubTreeParamsIn
mergeNode = R.createElement mergeNodeCpt
mergeNodeCpt :: R.Component SubTreeParamsIn
mergeNodeCpt = R.hooksComponentWithModule thisModule "mergeNode" cpt
where
cpt p@{dispatch, subTreeParams, id, nodeType, session, handed} _ = do
action@(valAction /\ setAction) :: R.State Action <- R.useState' (MergeNode {params:Nothing})
......
......@@ -14,6 +14,7 @@ import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTre
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node.Action.Move"
......@@ -22,8 +23,8 @@ moveNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
moveNodeReq session fromId toId =
put_ session $ NodeAPI GT.Node (Just fromId) ("move/" <> show toId)
moveNode :: Record SubTreeParamsIn -> R.Element
moveNode p = R.createElement moveNodeCpt p []
moveNode :: R2.Component SubTreeParamsIn
moveNode = R.createElement moveNodeCpt
moveNodeCpt :: R.Component SubTreeParamsIn
moveNodeCpt = R.hooksComponentWithModule thisModule "moveNode" cpt
......
......@@ -349,7 +349,6 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
inputWithEnter { onEnter: onEnter valueRef setSearch
, onValueChanged: onValueChanged valueRef
, autoFocus: false
, autoSave: true
, className: "form-control"
, defaultValue: R.readRef valueRef
, placeholder: "Your query here"
......@@ -380,10 +379,10 @@ type SubmitButtonProps =
submitButton :: Record SubmitButtonProps -> R.Element
submitButton p = R.createElement submitButtonComponent p []
where
submitButtonComponent :: R.Component SubmitButtonProps
submitButtonComponent = R.hooksComponentWithModule thisModule "submitButton" cpt
submitButtonComponent :: R.Component SubmitButtonProps
submitButtonComponent = R.hooksComponentWithModule thisModule "submitButton" cpt
where
cpt {onSearch, search: (mySearch /\ _), session} _ =
pure $
H.button { className: "btn btn-primary"
......
......@@ -274,13 +274,13 @@ panelActionCpt = R.hooksComponentWithModule thisModule "panelAction" cpt
-----------
-- Functions using SubTree
cpt {action: Merge {subTreeParams}, dispatch, id, nodeType, session, handed} _ = do
pure $ mergeNode {dispatch, id, nodeType, session, subTreeParams, handed}
pure $ mergeNode {dispatch, id, nodeType, session, subTreeParams, handed} []
cpt {action: Move {subTreeParams}, dispatch, id, nodeType, session, handed} _ = do
pure $ moveNode {dispatch, id, nodeType, session, subTreeParams, handed}
pure $ moveNode {dispatch, id, nodeType, session, subTreeParams, handed} []
cpt {action: Link {subTreeParams}, dispatch, id, nodeType, session, handed} _ = do
pure $ linkNode {dispatch, id, nodeType, session, subTreeParams, handed}
pure $ linkNode {dispatch, id, nodeType, session, subTreeParams, handed} []
-----------
cpt {action : Share, dispatch, id, name } _ = do
......
......@@ -65,12 +65,12 @@ type TextInputBoxProps =
)
textInputBox :: R2.Component TextInputBoxProps
textInputBox props@{ boxName } = R.createElement el props
where
el :: R.Component TextInputBoxProps
el = R.hooksComponentWithModule thisModule (boxName <> "Box") cpt
textInputBox = R.createElement textInputBoxCpt
cpt p@{ boxAction, dispatch, id, isOpen: (true /\ setIsOpen), text } _ = do
textInputBoxCpt :: R.Component TextInputBoxProps
textInputBoxCpt = R.hooksComponentWithModule thisModule "textInputBox" cpt
where
cpt p@{ boxAction, boxName, dispatch, id, isOpen: (true /\ setIsOpen), text } _ = do
renameNodeNameRef <- R.useRef text
pure $ H.div { className: "from-group row" }
......@@ -85,7 +85,6 @@ textInputBox props@{ boxName } = R.createElement el props
onEnter: submit renameNodeNameRef
, onValueChanged: R.setRef renameNodeNameRef
, autoFocus: true
, autoSave: false
, className: "form-control"
, defaultValue: text
, placeholder: (boxName <> " Node")
......@@ -105,8 +104,8 @@ textInputBox props@{ boxName } = R.createElement el props
, title: "Cancel"
} []
submit renameNodeNameRef _ = do
setIsOpen $ const false
launchAff_ $ dispatch ( boxAction $ R.readRef renameNodeNameRef )
setIsOpen $ const false
cpt { isOpen: (false /\ _) } _ = pure $ H.div {} []
-- | END Rename Box
......
......@@ -16,7 +16,6 @@ type Props a = (
, onValueChanged :: String -> Effect Unit
, autoFocus :: Boolean
, autoSave :: Boolean
, className :: String
, defaultValue :: String
, placeholder :: String
......@@ -25,12 +24,13 @@ type Props a = (
inputWithEnter :: forall a. Record (Props a) -> R.Element
inputWithEnter props = R.createElement inputWithEnterCpt props []
inputWithEnterCpt :: forall a. R.Component (Props a)
inputWithEnterCpt = R.hooksComponentWithModule thisModule "inputWithEnter" cpt
where
cpt props@{ onEnter, onValueChanged
, autoFocus, autoSave, className, defaultValue, placeholder } _ = do
pure $ H.input { on: { blur: \_ -> if autoSave then onEnter unit else pure unit
, autoFocus, className, defaultValue, placeholder } _ = do
pure $ H.input { on: { blur: \_ -> onEnter unit
, input: onInput
, keyPress: onKeyPress }
, autoFocus
......@@ -40,11 +40,7 @@ inputWithEnterCpt = R.hooksComponentWithModule thisModule "inputWithEnter" cpt
, type: props.type }
where
onInput e = do
if autoSave then
onValueChanged $ R.unsafeEventValue e
else
pure unit
onInput e = onValueChanged $ R.unsafeEventValue e
onKeyPress e = do
char <- R2.keyCode e
......
......@@ -128,7 +128,6 @@ contactInfoItemCpt = R.hooksComponentWithModule thisModule "contactInfoItem" cpt
H.div { className: "input-group col-sm-6" } [
inputWithEnter {
autoFocus: true
, autoSave: false
, className: "form-control"
, defaultValue: R.readRef valueRef
, onEnter: onClick
......
......@@ -307,7 +307,6 @@ renameableTextCpt = R.hooksComponentWithModule thisModule "renameableTextCpt" cp
pure $ H.div { className: "input-group" }
[ inputWithEnter {
autoFocus: false
, autoSave: false
, className: "form-control text"
, defaultValue: text
, onEnter: submit
......
......@@ -132,11 +132,11 @@ type CodeEditorProps =
)
dashboardCodeEditor :: R2.Component CodeEditorProps
dashboardCodeEditor = R.createElement el
where
el :: R.Component CodeEditorProps
el = R.hooksComponentWithModule thisModule "dashboardCodeEditor" cpt
dashboardCodeEditor = R.createElement dashboardCodeEditorCpt
dashboardCodeEditorCpt :: R.Component CodeEditorProps
dashboardCodeEditorCpt = R.hooksComponentWithModule thisModule "dashboardCodeEditor" cpt
where
cpt props@{ fields, nodeId, onChange, session } _ = do
let fieldsWithIndex = List.mapWithIndex (\idx -> \t -> Tuple idx t) fields
fieldsS <- R.useState' fieldsWithIndex
......
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