generate passord form error message

This commit is contained in:
Jonathan Lamothe 2024-09-12 20:09:13 -04:00
parent b0487d4d03
commit 8bddf35a1a
2 changed files with 17 additions and 11 deletions

View File

@ -22,10 +22,13 @@ License along with this program. If not, see
-}
{-# LANGUAGE OverloadedStrings #-}
module Password.App.Draw (drawFunc) where
import Brick (Widget, emptyWidget, txt, vBox)
import Brick.Forms (renderForm)
import Brick.Forms (Form, formState, renderForm)
import Data.Text (Text)
import Lens.Micro ((^.))
import Password.App.Types
@ -33,15 +36,21 @@ import Password.App.Types
-- | Renders the application view
drawFunc :: AppState -> [Widget ResName]
drawFunc s = case s^.appMode of
InitMode is -> drawPassForm is
InitMode is -> drawPassForm $ is^.setPassForm
_ -> [emptyWidget]
drawPassForm :: InitState -> [Widget ResName]
drawPassForm is =
drawPassForm :: Form (Text, Text) () ResName -> [Widget ResName]
drawPassForm f =
[ vBox
[ renderForm $ is^.setPassForm
, txt $ is^.spfError
[ renderForm f
, txt $ pfText $ formState f
]
]
pfText :: (Text, Text) -> Text
pfText (pass, conf)
| pass == "" = "Password cannot be blank."
| pass /= conf = "Passwords do not match."
| otherwise = ""
--jl

View File

@ -41,7 +41,6 @@ module Password.App.Types (
runState,
-- ** InitState
setPassForm,
spfError,
-- ** RunState
mainPass,
-- * Constructors
@ -76,14 +75,13 @@ data AppMode
} -- ^ initialization mode (master password form)
| RunMode
{ _runState :: RunState
-- ^ State of initialized app
} -- ^ Running mode
-- | Application initialization state
data InitState = InitState
newtype InitState = InitState
{ _setPassForm :: Form (Text, Text) () ResName
-- ^ password form
, _spfError :: Text
-- ^ error message
}
-- | State of the initialized application
@ -121,6 +119,5 @@ newInitState = InitState
]
("", "")
)
""
--jl