Let's select a domain!

beta
Philippe Pittoli 2023-07-02 00:05:38 +02:00
parent 8fe25f8aca
commit 8d32f9933b
3 changed files with 19 additions and 11 deletions

View File

@ -11,6 +11,7 @@
, "codec-argonaut" , "codec-argonaut"
, "console" , "console"
, "const" , "const"
, "dom-indexed"
, "effect" , "effect"
, "either" , "either"
, "exceptions" , "exceptions"

View File

@ -15,9 +15,11 @@ import Prelude
import Bulma as Bulma import Bulma as Bulma
import Halogen.HTML.Events as HHE
import Control.Monad.Except (runExcept) import Control.Monad.Except (runExcept)
import Control.Monad.State (class MonadState) import Control.Monad.State (class MonadState)
import Data.Array as A import Data.Array as A
-- import Data.Array.Partial as DAP
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import Data.Const (Const) import Data.Const (Const)
@ -154,6 +156,7 @@ data Action
| UpdateAcceptedDomains (Array String) | UpdateAcceptedDomains (Array String)
| UpdateMyDomains (Array String) | UpdateMyDomains (Array String)
| UpdateSelectedDomain String
| AuthenticateToDNSManager | AuthenticateToDNSManager
@ -174,6 +177,7 @@ type State =
, newDomainForm :: NewDomainFormState , newDomainForm :: NewDomainFormState
, accepted_domains :: Array String , accepted_domains :: Array String
, selected_domain :: String
, my_domains :: Array String , my_domains :: Array String
-- TODO: put network stuff in a record. -- TODO: put network stuff in a record.
@ -194,6 +198,9 @@ component =
} }
} }
default_domain :: String
default_domain = "netlib.re"
initialState :: Input -> State initialState :: Input -> State
initialState (Tuple url token) = initialState (Tuple url token) =
{ messages: [] { messages: []
@ -202,7 +209,8 @@ initialState (Tuple url token) =
, token: token , token: token
, newDomainForm: { new_domain: "" } , newDomainForm: { new_domain: "" }
, accepted_domains: [ "netlib.re" ] , accepted_domains: [ default_domain ]
, selected_domain: default_domain
, my_domains: [ ] , my_domains: [ ]
-- TODO: put network stuff in a record. -- TODO: put network stuff in a record.
@ -221,7 +229,6 @@ render {
newDomainForm } newDomainForm }
= HH.div_ = HH.div_
[ Bulma.columns_ [ Bulma.column_ newdomain_form [ Bulma.columns_ [ Bulma.column_ newdomain_form
, Bulma.column_ list_acceptable_domains
, Bulma.column_ list_of_own_domains ] , Bulma.column_ list_of_own_domains ]
, render_messages , render_messages
, renderReconnectButton (isNothing wsConnection && canReconnect) , renderReconnectButton (isNothing wsConnection && canReconnect)
@ -233,11 +240,6 @@ render {
, render_adduser_form , render_adduser_form
] ]
list_acceptable_domains
= [ Bulma.h3 "Acceptable domains:"
, Bulma.select $ map Bulma.option accepted_domains
]
list_of_own_domains list_of_own_domains
= [ Bulma.h3 "My domains:" = [ Bulma.h3 "My domains:"
, HH.ul_ $ map (\domain -> HH.li_ [ HH.text domain ]) my_domains , HH.ul_ $ map (\domain -> HH.li_ [ HH.text domain ]) my_domains
@ -253,6 +255,7 @@ render {
true -- validity (TODO) true -- validity (TODO)
should_be_disabled -- condition should_be_disabled -- condition
-- TODO: list of options for TLD -- TODO: list of options for TLD
, Bulma.select [ HHE.onSelectedIndexChange (\i -> UpdateSelectedDomain $ maybe "netlib.re" (\x -> x) $ accepted_domains A.!! i) ] $ map Bulma.option accepted_domains
, HH.div_ , HH.div_
[ HH.button [ HH.button
[ HP.style "padding: 0.5rem 1.25rem;" [ HP.style "padding: 0.5rem 1.25rem;"
@ -314,6 +317,9 @@ handleAction = case _ of
UpdateMyDomains domains -> do UpdateMyDomains domains -> do
H.modify_ _ { my_domains = domains } H.modify_ _ { my_domains = domains }
UpdateSelectedDomain domain -> do
H.modify_ _ { selected_domain = domain }
AuthenticateToDNSManager -> do AuthenticateToDNSManager -> do
{ wsConnection, token } <- H.get { wsConnection, token } <- H.get
appendMessage $ "[🤖] Trying to authenticate..." appendMessage $ "[🤖] Trying to authenticate..."

View File

@ -4,7 +4,7 @@ module Bulma where
import Prelude import Prelude
import Halogen.HTML as HH import Halogen.HTML as HH
-- import DOM.HTML.Indexed as DHI import DOM.HTML.Indexed as DHI
import Halogen.HTML.Properties as HP import Halogen.HTML.Properties as HP
import Halogen.HTML.Events as HE import Halogen.HTML.Events as HE
@ -337,6 +337,7 @@ box = HH.div [HP.classes class_box]
option :: forall w i. String -> HH.HTML w i option :: forall w i. String -> HH.HTML w i
option value = HH.option_ [HH.text value] option value = HH.option_ [HH.text value]
select :: forall w i. Array (HH.HTML w i) -> HH.HTML w i select :: forall w i. HH.Node DHI.HTMLselect w i
select options = HH.div [HP.classes (class_select <> class_primary)] select action options
[ HH.select_ options] = HH.div [ HP.classes (class_select <> class_primary) ]
[ HH.select action options]