Type simplification.
parent
e9808e70f1
commit
ad6a64d78a
|
@ -148,6 +148,7 @@ type Input = Tuple String String
|
||||||
|
|
||||||
data NewDomainFormAction
|
data NewDomainFormAction
|
||||||
= INP_newdomain String
|
= INP_newdomain String
|
||||||
|
| UpdateSelectedDomain String
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= Initialize
|
= Initialize
|
||||||
|
@ -156,7 +157,6 @@ data Action
|
||||||
|
|
||||||
| UpdateAcceptedDomains (Array String)
|
| UpdateAcceptedDomains (Array String)
|
||||||
| UpdateMyDomains (Array String)
|
| UpdateMyDomains (Array String)
|
||||||
| UpdateSelectedDomain String
|
|
||||||
|
|
||||||
| AuthenticateToDNSManager
|
| AuthenticateToDNSManager
|
||||||
|
|
||||||
|
@ -166,8 +166,10 @@ data Action
|
||||||
-- | Finalize
|
-- | Finalize
|
||||||
| HandleWebSocket (WebSocketEvent WebSocketMessageType)
|
| HandleWebSocket (WebSocketEvent WebSocketMessageType)
|
||||||
|
|
||||||
-- TODO: TLD
|
type NewDomainFormState
|
||||||
type NewDomainFormState = { new_domain :: String }
|
= { new_domain :: String
|
||||||
|
, selected_domain :: String
|
||||||
|
}
|
||||||
|
|
||||||
type State =
|
type State =
|
||||||
{ messages :: Array String
|
{ messages :: Array String
|
||||||
|
@ -177,7 +179,6 @@ 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.
|
||||||
|
@ -207,10 +208,11 @@ initialState (Tuple url token) =
|
||||||
, messageHistoryLength: 10
|
, messageHistoryLength: 10
|
||||||
|
|
||||||
, token: token
|
, token: token
|
||||||
, newDomainForm: { new_domain: "" }
|
, newDomainForm: { new_domain: ""
|
||||||
|
, selected_domain: default_domain
|
||||||
|
}
|
||||||
|
|
||||||
, accepted_domains: [ default_domain ]
|
, 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.
|
||||||
|
@ -254,8 +256,7 @@ render {
|
||||||
newDomainForm.new_domain -- value
|
newDomainForm.new_domain -- value
|
||||||
true -- validity (TODO)
|
true -- validity (TODO)
|
||||||
should_be_disabled -- condition
|
should_be_disabled -- condition
|
||||||
-- TODO: list of options for TLD
|
, domain_selection
|
||||||
, 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;"
|
||||||
|
@ -266,6 +267,12 @@ render {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
domain_selection = Bulma.select [ HHE.onSelectedIndexChange domain_choice ] $ map Bulma.option accepted_domains
|
||||||
|
domain_choice :: Int -> Action
|
||||||
|
domain_choice i
|
||||||
|
= HandleNewDomainInput <<< UpdateSelectedDomain $ maybe "netlib.re" (\x -> x) $ accepted_domains A.!! i
|
||||||
|
|
||||||
|
|
||||||
render_messages = HH.ul_ $ map (\msg -> HH.li_ [ HH.text msg ]) messages
|
render_messages = HH.ul_ $ map (\msg -> HH.li_ [ HH.text msg ]) messages
|
||||||
|
|
||||||
renderFootnote :: String -> H.ComponentHTML Action () m
|
renderFootnote :: String -> H.ComponentHTML Action () m
|
||||||
|
@ -317,9 +324,6 @@ 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..."
|
||||||
|
@ -331,13 +335,15 @@ handleAction = case _ of
|
||||||
|
|
||||||
HandleNewDomainInput adduserinp -> do
|
HandleNewDomainInput adduserinp -> do
|
||||||
case adduserinp of
|
case adduserinp of
|
||||||
INP_newdomain v -> H.modify_ _ { newDomainForm { new_domain = v } }
|
INP_newdomain v -> H.modify_ _ { newDomainForm { new_domain = v } }
|
||||||
|
UpdateSelectedDomain domain -> do
|
||||||
|
H.modify_ _ { newDomainForm { selected_domain = domain } }
|
||||||
|
|
||||||
NewDomainAttempt ev -> do
|
NewDomainAttempt ev -> do
|
||||||
H.liftEffect $ Event.preventDefault ev
|
H.liftEffect $ Event.preventDefault ev
|
||||||
|
|
||||||
{ wsConnection, newDomainForm, selected_domain } <- H.get
|
{ wsConnection, newDomainForm } <- H.get
|
||||||
let new_domain = newDomainForm.new_domain
|
let new_domain = newDomainForm.new_domain <> newDomainForm.selected_domain
|
||||||
|
|
||||||
case wsConnection, new_domain of
|
case wsConnection, new_domain of
|
||||||
Nothing, _ ->
|
Nothing, _ ->
|
||||||
|
@ -362,7 +368,7 @@ handleAction = case _ of
|
||||||
|
|
||||||
Open -> do
|
Open -> do
|
||||||
H.liftEffect $ do
|
H.liftEffect $ do
|
||||||
ab <- DNSManager.serialize $ DNSManager.MkNewDomain { domain: (new_domain <> "." <> selected_domain) }
|
ab <- DNSManager.serialize $ DNSManager.MkNewDomain { domain: new_domain }
|
||||||
sendArrayBuffer webSocket ab
|
sendArrayBuffer webSocket ab
|
||||||
appendMessageReset "[😇] Trying to add a new domain"
|
appendMessageReset "[😇] Trying to add a new domain"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue