From c42cbbeb8ae343d9f413bf05f58b436d7bd1c549 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Fri, 2 Jun 2023 20:05:03 +0200 Subject: [PATCH] Authentication form now informs when there is a failed authentication attempt. --- src/App/AuthenticationForm.purs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/App/AuthenticationForm.purs b/src/App/AuthenticationForm.purs index 7a132c1..f5db757 100644 --- a/src/App/AuthenticationForm.purs +++ b/src/App/AuthenticationForm.purs @@ -191,14 +191,18 @@ wrapperStyle = """ render :: forall m. State -> H.ComponentHTML Action () m -render { messages, loginInputText, passInputText, wsConnection, canReconnect, messageHistoryLength } = +render { messages, loginInputText, passInputText, wsConnection, canReconnect } = HH.div [ HP.style wrapperStyle ] [ HH.h2_ [ HH.text "Authentication!" ] - , HH.form + , render_auth_form + , render_messages + ] + where + + render_auth_form = HH.form [ HE.onSubmit AuthenticationAttempt ] - [ HH.ul_ $ map (\msg -> HH.li_ [ HH.text msg ]) messages - , HH.p_ + [ HH.p_ [ HH.div_ [ HH.input [ HP.style "padding: 0.5rem 0.75rem; margin-bottom: 0.25rem;" @@ -226,18 +230,19 @@ render { messages, loginInputText, passInputText, wsConnection, canReconnect, me [ HH.text "Send Message to Server" ] ] ] - , renderMaxHistoryLength messageHistoryLength + --, renderMaxHistoryLength messageHistoryLength , renderReconnectButton (isNothing wsConnection && canReconnect) ] - ] - where + + render_messages = HH.ul_ $ map (\msg -> HH.li_ [ HH.text msg ]) messages + renderFootnote :: String -> H.ComponentHTML Action () m renderFootnote txt = HH.div [ HP.style "margin-bottom: 0.125rem; color: grey;" ] [ HH.small_ [ HH.text txt ] ] - renderMaxHistoryLength :: Int -> H.ComponentHTML Action () m - renderMaxHistoryLength len = - renderFootnote ("NOTE: Maximum chat history length is " <> show len <> " messages") + -- renderMaxHistoryLength :: Int -> H.ComponentHTML Action () m + -- renderMaxHistoryLength len = + -- renderFootnote ("NOTE: Maximum chat history length is " <> show len <> " messages") renderReconnectButton :: Boolean -> H.ComponentHTML Action () m renderReconnectButton cond = @@ -253,7 +258,6 @@ render { messages, loginInputText, passInputText, wsConnection, canReconnect, me else HH.p_ [ renderFootnote "NOTE: A 'Reconnect?' button will appear if the connection drops" - , renderFootnote "NOTE: You can type /disconnect to manually disconnect" ] handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit @@ -338,8 +342,8 @@ handleAction = case _ of Right response -> do case response of -- The authentication failed. - (AuthD.GotError _) -> do - appendMessage $ "[😈] Failed! (TODO: put the reason)" + (AuthD.GotError errmsg) -> do + appendMessage $ "[😈] Failed: " <> maybe "server didn't tell why" (\v -> v) errmsg.reason -- The authentication was a success! (AuthD.GotToken msg) -> do appendMessage $ "[😈] Success! user " <> (show msg.uid) <> " has token: " <> msg.token