diff --git a/src/App/ComponentA.purs b/src/App/ComponentA.purs deleted file mode 100644 index 98ee02c..0000000 --- a/src/App/ComponentA.purs +++ /dev/null @@ -1,51 +0,0 @@ -module App.ComponentA where - -import Prelude - -import Data.Maybe (Maybe(..)) - -import Halogen as H -import Halogen.HTML as HH -import Halogen.HTML.Events as HE - -type Slot = H.Slot Query Void - -data Query a = IsOn (Boolean -> a) - -data Action = Toggle - -type State = Boolean - -component :: forall i o m. H.Component Query i o m -component = - H.mkComponent - { initialState - , render - , eval: H.mkEval $ H.defaultEval - { handleAction = handleAction - , handleQuery = handleQuery - } - } - -initialState :: forall i. i -> State -initialState _ = false - -render :: forall m. State -> H.ComponentHTML Action () m -render state = - HH.div_ - [ HH.p_ [ HH.text "Toggle me!" ] - , HH.button - [ HE.onClick \_ -> Toggle ] - [ HH.text (if state then "On" else "Off") ] - ] - -handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit -handleAction = case _ of - Toggle -> - H.modify_ not - -handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a) -handleQuery = case _ of - IsOn k -> do - enabled <- H.get - pure (Just (k enabled)) diff --git a/src/App/ComponentB.purs b/src/App/ComponentB.purs deleted file mode 100644 index 481a1da..0000000 --- a/src/App/ComponentB.purs +++ /dev/null @@ -1,53 +0,0 @@ -module App.ComponentB where - -import Prelude - -import Data.Maybe (Maybe(..)) - -import Halogen as H -import Halogen.HTML as HH -import Halogen.HTML.Events as HE - -type Slot = H.Slot Query Void - -data Query a = GetCount (Int -> a) - -data Action = Increment - -type State = Int - -component :: forall i o m. H.Component Query i o m -component = - H.mkComponent - { initialState - , render - , eval: H.mkEval $ H.defaultEval - { handleAction = handleAction - , handleQuery = handleQuery - } - } - -initialState :: forall i. i -> State -initialState _ = 0 - -render :: forall m. State -> H.ComponentHTML Action () m -render state = - HH.div_ - [ HH.p_ - [ HH.text "Current value:" - , HH.strong_ [ HH.text (show state) ] - ] - , HH.button - [ HE.onClick \_ -> Increment ] - [ HH.text ("Increment") ] - ] - -handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit -handleAction = case _ of - Increment -> - H.modify_ (_ + 1) - -handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a) -handleQuery = case _ of - GetCount k -> - Just <<< k <$> H.get diff --git a/src/App/ComponentC.purs b/src/App/ComponentC.purs deleted file mode 100644 index fa385a2..0000000 --- a/src/App/ComponentC.purs +++ /dev/null @@ -1,52 +0,0 @@ -module App.ComponentC where - -import Prelude - -import Data.Maybe (Maybe(..)) - -import Halogen as H -import Halogen.HTML as HH -import Halogen.HTML.Events as HE -import Halogen.HTML.Properties as HP - -type Slot = H.Slot Query Void - -data Query a = GetValue (String -> a) - -data Action = HandleInput String - -type State = String - -component :: forall i o m. H.Component Query i o m -component = - H.mkComponent - { initialState - , render - , eval: H.mkEval $ H.defaultEval - { handleAction = handleAction - , handleQuery = handleQuery - } - } - -initialState :: forall i. i -> State -initialState _ = "Hello" - -render :: forall m. State -> H.ComponentHTML Action () m -render state = - HH.label_ - [ HH.p_ [ HH.text "What do you have to say?" ] - , HH.input - [ HP.value state - , HE.onValueInput HandleInput - ] - ] - -handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit -handleAction = case _ of - HandleInput value -> - H.put value - -handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a) -handleQuery = case _ of - GetValue k -> - Just <<< k <$> H.get diff --git a/src/App/Container.purs b/src/App/Container.purs index 62cbb65..d9701ab 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -3,11 +3,7 @@ module App.Container where import Prelude import Data.Maybe (Maybe(..)) -import App.ComponentA as CA -import App.ComponentB as CB -import App.ComponentC as CC import App.AuthenticationForm as AF -import App.OriginalInterface as OI import Halogen as H import Halogen.HTML as HH -- import Halogen.HTML.Events as HE @@ -15,28 +11,16 @@ import Halogen.HTML.Properties as HP import Type.Proxy (Proxy(..)) import Effect.Aff.Class (class MonadAff) -data Action = ReadStates | Authenticated AF.Output +data Action + = Authenticated AF.Output -- User has been authenticated. -type State = - { a :: Maybe Boolean - , b :: Maybe Int - , c :: Maybe String - , token :: Maybe String - } +type State = { token :: Maybe String } type ChildSlots = - ( a :: CA.Slot Unit - , b :: CB.Slot Unit - , c :: CC.Slot Unit - , af :: AF.Slot Unit - , oi :: OI.Slot Unit + ( af :: AF.Slot Unit ) -_a = Proxy :: Proxy "a" -_b = Proxy :: Proxy "b" -_c = Proxy :: Proxy "c" _af = Proxy :: Proxy "af" -_oi = Proxy :: Proxy "oi" component :: forall q i o m. MonadAff m => H.Component q i o m component = @@ -47,15 +31,13 @@ component = } initialState :: forall i. i -> State -initialState _ = { a: Nothing, b: Nothing, c: Nothing, token: Nothing } +initialState _ = { token: Nothing } render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m render state = HH.div_ $ [ render_auth_form , div_token - --, render_original_interface - --, useless_stuff ] where div_token :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad @@ -75,50 +57,7 @@ render state [ HP.class_ (H.ClassName "box") ] [ HH.p_ [ HH.text ("Token is: " <> current_token) ] ] - --render_original_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad - --render_original_interface = - -- HH.div - -- [ HP.class_ (H.ClassName "box") ] - -- [ HH.h1_ [ HH.text "Original interface" ] - -- , HH.slot_ _oi unit OI.component "ws://127.0.0.1:8080" - -- ] - - -- useless_stuff :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad - -- useless_stuff = - -- HH.div_ [ - -- HH.div - -- [ HP.class_ (H.ClassName "box") ] - -- [ HH.h1_ [ HH.text "Component A" ] - -- , HH.slot_ _a unit CA.component unit - -- ] - -- , HH.div - -- [ HP.class_ (H.ClassName "box") ] - -- [ HH.h1_ [ HH.text "Component B" ] - -- , HH.slot_ _b unit CB.component unit - -- ] - -- , HH.div - -- [ HP.class_ (H.ClassName "box") ] - -- [ HH.h1_ [ HH.text "Component C" ] - -- , HH.slot_ _c unit CC.component unit - -- ] - -- , HH.p_ - -- [ HH.text "Last observed states:" ] - -- , HH.ul_ - -- [ HH.li_ [ HH.text ("Component A: " <> show state.a) ] - -- , HH.li_ [ HH.text ("Component B: " <> show state.b) ] - -- , HH.li_ [ HH.text ("Component C: " <> show state.c) ] - -- ] - -- , HH.button - -- [ HE.onClick \_ -> ReadStates ] - -- [ HH.text "Check states now" ] - -- ] handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit handleAction = case _ of Authenticated (AF.AuthToken newtoken) -> H.modify_ _ { token = Just newtoken } - ReadStates -> do - { token } <- H.get - a <- H.request _a unit CA.IsOn - b <- H.request _b unit CB.GetCount - c <- H.request _c unit CC.GetValue - H.put { a, b, c, token }