Commit 91cd00aa authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by James Laver

[Layout] rewrite divDropdownRight with end config chooser

parent 31f1b390
...@@ -4,7 +4,9 @@ import Data.Foldable (fold, intercalate) ...@@ -4,7 +4,9 @@ import Data.Foldable (fold, intercalate)
import Data.Lens (over) import Data.Lens (over)
import Data.Maybe (Maybe(Nothing, Just)) import Data.Maybe (Maybe(Nothing, Just))
import Data.Tuple.Nested((/\)) import Data.Tuple.Nested((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff)
import React.DOM (button, div, text) import React.DOM (button, div, text)
import React.DOM.Props (_id, className, onClick, role, style) import React.DOM.Props (_id, className, onClick, role, style)
import Reactix as R import Reactix as R
...@@ -123,7 +125,7 @@ layout0 layout = ...@@ -123,7 +125,7 @@ layout0 layout =
Nothing -> Nothing ->
className "col-md-12" className "col-md-12"
] (render d p s c) ] ] (render d p s c) ]
cont = over _render \render d p s c -> [ div [className "row" ] (render d p s c) ] cont = over _render \render d p s c -> [ div [className "row" ] (render d p s c) ]
--as = noState Tree.treeview --as = noState Tree.treeview
bs = innerLayout $ layout bs = innerLayout $ layout
...@@ -348,14 +350,49 @@ logLinks d s = case s.loginState.authData of ...@@ -348,14 +350,49 @@ logLinks d s = case s.loginState.authData of
[H.text " Logout"] [H.text " Logout"]
divDropdownRight :: (Action -> Effect Unit) -> AppState -> R.Element
divDropdownRight d s = R.createElement el {state: s} []
where
el = R.hooksComponent "DivDropdownRight" cpt
cpt {state} _children = do
(configState /\ setConfigState) <- R.useState' state.configState
pure $ H.ul {className: "nav navbar-nav pull-right"}
[ endConfigChooserCpt d state.configState (configState /\ setConfigState)
, logLinks d state
]
endConfigChooserCpt d s (configState /\ setConfigState) = R.createElement el {state: s} []
where
el = R.hooksComponent "EndConfigChooserCpt" cpt
cpt {state} _children = do
R.useEffect $ pure $
if (configState /= state) then do
_ <- log2 "update state: " configState
_ <- d $ ConfigStateA $ C.UpdateState configState
_ <- log2 "logout" ""
d $ Logout
else
pure $ unit
pure $ H.span {}
[ endConfigChooser (configState /\ setConfigState)
, H.span {className: "text-info"}
[ H.text $ C.endConfigDisplayName configState.endConfig ]
, H.span {className: "text-danger"}
[ H.text $ C.endConfigDisplayName state.endConfig ]
]
endConfigChooser :: R.State C.State -> R.Element endConfigChooser :: R.State C.State -> R.Element
endConfigChooser (configState /\ setConfigState) = R.createElement el {} [] endConfigChooser (configState /\ setConfigState) = R.createElement el {} []
where where
el = R.hooksComponent "EndConfigChooser" cpt el = R.hooksComponent "EndConfigChooser" cpt
cpt {} _ = do cpt {} _ = do
-- NOTE Need to rebind the component after rerender -- NOTE Need to rebind the component after rerender
R.useEffect $ R.useEffect do
pure $ createDropdown "end-config-chooser" _ <- pure $ createDropdown "end-config-chooser"
pure $ pure unit
pure $ H.li {className: "dropdown"} pure $ H.li {className: "dropdown"}
[ H.a { className: "navbar-text dropdown-toggle" [ H.a { className: "navbar-text dropdown-toggle"
...@@ -371,28 +408,12 @@ endConfigChooser (configState /\ setConfigState) = R.createElement el {} [] ...@@ -371,28 +408,12 @@ endConfigChooser (configState /\ setConfigState) = R.createElement el {} []
liItem :: C.EndConfigOption -> R.Element liItem :: C.EndConfigOption -> R.Element
liItem {endConfig, displayName} = liItem {endConfig, displayName} =
H.li {on: {click: \_ -> setConfigState $ \st -> st {endConfig = endConfig}}} H.li {on: {click: onClick endConfig}}
--H.li {}
[ H.a {href: "#"} [H.text displayName] ] [ H.a {href: "#"} [H.text displayName] ]
onClick endConfig = \_ -> do
divDropdownRight :: (Action -> Effect Unit) -> AppState -> R.Element log2 "set end config" endConfig
divDropdownRight d s = R.createElement el {} [] setConfigState $ \st -> st {endConfig = endConfig}
where
el = R.hooksComponent "DivDropdownRight" cpt
cpt {} _children = do
(configState /\ setConfigState) <- R.useState' s.configState
R.useEffect $
if (configState /= s.configState) then do
pure $ d $ ConfigStateA $ C.UpdateState configState
else
pure $ pure $ unit
pure $ H.ul {className: "nav navbar-nav pull-right"}
[ endConfigChooser (configState /\ setConfigState)
, logLinks d s
]
layoutFooter :: Spec {} {} Void layoutFooter :: Spec {} {} Void
layoutFooter = R2.elSpec $ R.hooksComponent "LayoutFooter" cpt layoutFooter = R2.elSpec $ R.hooksComponent "LayoutFooter" cpt
......
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