From 99fb18c57a078dc09449b3decf1a9a28b5646bb4 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 3 Jul 2023 04:31:00 +0200 Subject: [PATCH] Can now delete a domain. No automatic domain list update. --- src/App/DNSManagerDomainsInterface.purs | 52 ++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/App/DNSManagerDomainsInterface.purs b/src/App/DNSManagerDomainsInterface.purs index 4309ca0..4122bf8 100644 --- a/src/App/DNSManagerDomainsInterface.purs +++ b/src/App/DNSManagerDomainsInterface.purs @@ -5,7 +5,8 @@ module App.DNSManagerDomainsInterface where - display the list of own domains - show and select accepted domains (TLDs) - create new domains - - TODO: delete a domain (+ TODO: ask for confirmation) + - delete a domain + - TODO: ask for confirmation - TODO: show and modify the content of a Zone Authentication is automatic with the token. @@ -73,6 +74,8 @@ data Action | HandleNewDomainInput NewDomainFormAction | NewDomainAttempt Event + | RemoveDomain String + | EnterDomain String | Finalize | HandleWebSocket (WebSocketEvent WebSocketMessageType) @@ -155,7 +158,24 @@ render { list_of_own_domains = [ Bulma.h3 "My domains:" - , HH.ul_ $ map (\domain -> HH.li_ [ HH.text domain ]) my_domains + , HH.ul_ $ map (\domain -> HH.li_ (domain_buttons domain)) my_domains + ] + + domain_buttons domain + = [ HH.button + [ HP.style "padding: 0.5rem 1.25rem;" + , HP.type_ HP.ButtonSubmit + , HE.onClick \_ -> EnterDomain domain + , maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection + ] + [ HH.text domain ] + , HH.button + [ HP.style "padding: 0.5rem 1.25rem;" + , HP.type_ HP.ButtonSubmit + , HE.onClick \_ -> RemoveDomain domain + , maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection + ] + [ HH.text "x" ] ] should_be_disabled = (maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection) @@ -250,6 +270,34 @@ handleAction = case _ of UpdateSelectedDomain domain -> do H.modify_ _ { newDomainForm { selected_domain = domain } } + EnterDomain domain -> do + appendMessage $ "[???] trying to enter domain: " <> domain + + RemoveDomain domain -> do + { wsInfo } <- H.get + case wsInfo.connection of + Nothing -> + unableToSend "Not connected to server." + Just webSocket -> + H.liftEffect (WS.readyState webSocket) >>= case _ of + Connecting -> + unableToSend "Still connecting to server." + + Closing -> + unableToSend "Connection to server is closing." + + Closed -> do + unableToSend "Connection to server has been closed." + maybeCurrentConnection <- H.gets _.wsInfo.connection + when (isJust maybeCurrentConnection) do + H.modify_ _ { wsInfo { connection = Nothing, reconnect = true } } + + Open -> do + H.liftEffect $ do + ab <- DNSManager.serialize $ DNSManager.MkDeleteDomain { domain: domain } + sendArrayBuffer webSocket ab + appendMessageReset $ "[😇] Removing domain: " <> domain + NewDomainAttempt ev -> do H.liftEffect $ Event.preventDefault ev