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