From 529c2edae7e9f3ea67a0c0f9538f7b41ce7445dd Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 18 Feb 2024 02:53:30 +0100 Subject: [PATCH] Make the code flow clearer. --- src/App/Container.purs | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/App/Container.purs b/src/App/Container.purs index 706464f..8db5b80 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -590,37 +590,40 @@ handleAction = case _ of state <- H.get case state.current_page, message of Home, m@(DNSManager.MkLogged _) -> do - case state.store_DomainListInterface_state of - Nothing -> do - let new_value = DomainListInterface.page_reload (DomainListInterface.initialState unit) m - H.modify_ _ { store_DomainListInterface_state = Just new_value } - Just _ -> handleAction $ Log $ SystemLog "we already have a state? WTH?!" - - -- Get back to the previous page. - sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window - page <- H.liftEffect $ Storage.getItem "current-page" sessionstorage - case page of - Nothing -> pure unit - Just "Home" -> handleAction $ Routing Home - Just "Authentication" -> handleAction $ Routing Authentication - Just "Registration" -> handleAction $ Routing Registration - Just "DomainList" -> handleAction $ Routing DomainList - Just "MailValidation" -> handleAction $ Routing MailValidation - - Just "Zone" -> do - domain <- H.liftEffect $ Storage.getItem "current-zone" sessionstorage - case domain of - Nothing -> handleAction $ Log $ SystemLog "Zone but no domain recorded!! WEIRD" - Just zone -> do handleAction $ Log $ SystemLog $ "zone to display: " <> zone - handleAction $ Routing (Zone zone) - - Just "AuthAdmin" -> handleAction $ Routing AuthAdmin - Just p -> handleAction $ Log $ SystemLog $ "Oopsie, we didn't understand the old page: " <> p - + update_domain_list state m + revert_old_page DomainList, _ -> H.tell _dli unit (DomainListInterface.MessageReceived message) Zone _ , _ -> H.tell _zi unit (ZoneInterface.MessageReceived message) _, _ -> handleAction $ Log $ SystemLog "unexpected message from dnsmanagerd" pure unit + where + update_domain_list state m = do + case state.store_DomainListInterface_state of + Nothing -> do + let new_value = DomainListInterface.page_reload (DomainListInterface.initialState unit) m + H.modify_ _ { store_DomainListInterface_state = Just new_value } + Just _ -> handleAction $ Log $ SystemLog "we already have a state? WTH?!" + + revert_old_page = do + -- Get back to the previous page. + sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window + page <- H.liftEffect $ Storage.getItem "current-page" sessionstorage + case page of + Nothing -> pure unit + Just "Home" -> handleAction $ Routing Home + Just "Authentication" -> handleAction $ Routing Authentication + Just "Registration" -> handleAction $ Routing Registration + Just "DomainList" -> handleAction $ Routing DomainList + Just "MailValidation" -> handleAction $ Routing MailValidation + Just "AuthAdmin" -> handleAction $ Routing AuthAdmin + Just "Zone" -> do + domain <- H.liftEffect $ Storage.getItem "current-zone" sessionstorage + case domain of + Nothing -> handleAction $ Log $ SystemLog "Zone but no domain recorded!! WEIRD" + Just zone -> do handleAction $ Log $ SystemLog $ "zone to display: " <> zone + handleAction $ Routing (Zone zone) + Just p -> handleAction $ Log $ SystemLog $ "Oopsie, we didn't understand the old page: " <> p + --print_json_string :: forall m. MonadEffect m => MonadState State m => ArrayBuffer -> m Unit --print_json_string arraybuffer = do