don't edit goalie stats when no input entered

This commit is contained in:
Jonathan Lamothe 2020-01-01 23:36:37 -05:00
parent 30807b7e2e
commit 9606436e9e

View File

@ -37,12 +37,13 @@ module Mtlstats.Prompt.EditGoalie
, editGoalieLtTiesPrompt , editGoalieLtTiesPrompt
) where ) where
import Control.Monad.Trans.State (modify) import Control.Monad.Extra (whenJustM)
import Lens.Micro ((.~)) import Control.Monad.Trans.State (gets, modify)
import Lens.Micro ((^.), (.~), (%~))
import Mtlstats.Actions.EditGoalie
import Mtlstats.Prompt import Mtlstats.Prompt
import Mtlstats.Types import Mtlstats.Types
import Mtlstats.Util
-- | Prompt to select a 'Goalie' for editing -- | Prompt to select a 'Goalie' for editing
goalieToEditPrompt :: Prompt goalieToEditPrompt :: Prompt
@ -51,70 +52,90 @@ goalieToEditPrompt = selectGoaliePrompt "Goalie to edit: " $
-- | Prompt to edit a goalie's number -- | Prompt to edit a goalie's number
editGoalieNumberPrompt :: Prompt editGoalieNumberPrompt :: Prompt
editGoalieNumberPrompt = numPrompt "Goalie number: " $ editGoalieNumberPrompt = editNum "Goalie number: " EGMenu
modify . editGoalieNumber (gNumber .~)
-- | Prompt to edit a goalie's name -- | Prompt to edit a goalie's name
editGoalieNamePrompt :: Prompt editGoalieNamePrompt :: Prompt
editGoalieNamePrompt = namePrompt "Goalie name: " $ editGoalieNamePrompt = namePrompt "Goalie name: " $ \name ->
modify . editGoalieName if null name
then goto EGMenu
else editGoalie EGMenu $ gName .~ name
-- | Prompt to edit a goalie's YTD games played -- | Prompt to edit a goalie's YTD games played
editGoalieYtdGamesPrompt :: Prompt editGoalieYtdGamesPrompt :: Prompt
editGoalieYtdGamesPrompt = numPrompt "Year-to-date games played: " $ editGoalieYtdGamesPrompt = editNum "Year-to-date games played: " EGYtd
modify . editGoalieYtdGames (gYtd.gsGames .~)
-- | Prompt to edit a goalie's YTD minutes played -- | Prompt to edit a goalie's YTD minutes played
editGoalieYtdMinsPrompt :: Prompt editGoalieYtdMinsPrompt :: Prompt
editGoalieYtdMinsPrompt = numPrompt "Year-to-date minutes played: " $ editGoalieYtdMinsPrompt = editNum "Year-to-date minutes played: " EGYtd
modify . editGoalieYtdMins (gYtd.gsMinsPlayed .~)
-- | Prompt to edit a goalie's YTD goales allowed -- | Prompt to edit a goalie's YTD goales allowed
editGoalieYtdGoalsPrompt :: Prompt editGoalieYtdGoalsPrompt :: Prompt
editGoalieYtdGoalsPrompt = numPrompt "Year-to-date goals allowed: " $ editGoalieYtdGoalsPrompt = editNum "Year-to-date goals allowed: " EGYtd
modify . editGoalieYtdGoals (gYtd.gsGoalsAllowed .~)
-- | Prompt to edit a goalie's YTD wins -- | Prompt to edit a goalie's YTD wins
editGoalieYtdWinsPrompt :: Prompt editGoalieYtdWinsPrompt :: Prompt
editGoalieYtdWinsPrompt = numPrompt "Year-to-date wins: " $ editGoalieYtdWinsPrompt = editNum "Year-to-date wins: " EGYtd
modify . editGoalieYtdWins (gYtd.gsWins .~)
-- | Prompt to edit a goalie's YTD losses -- | Prompt to edit a goalie's YTD losses
editGoalieYtdLossesPrompt :: Prompt editGoalieYtdLossesPrompt :: Prompt
editGoalieYtdLossesPrompt = numPrompt "Year-to-date losses: " $ editGoalieYtdLossesPrompt = editNum "Year-to-date losses: " EGYtd
modify . editGoalieYtdLosses (gYtd.gsLosses .~)
-- | Prompt to edit a goalie's YTD ties -- | Prompt to edit a goalie's YTD ties
editGoalieYtdTiesPrompt :: Prompt editGoalieYtdTiesPrompt :: Prompt
editGoalieYtdTiesPrompt = numPrompt "Year-to-date ties: " $ editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd
modify . editGoalieYtdTies (gYtd.gsTies .~)
-- | Prompt to edit a goalie's lifetime games played -- | Prompt to edit a goalie's lifetime games played
editGoalieLtGamesPrompt :: Prompt editGoalieLtGamesPrompt :: Prompt
editGoalieLtGamesPrompt = numPrompt "Lifetime games played: " $ editGoalieLtGamesPrompt = editNum "Lifetime games played: " EGLifetime
modify . editGoalieLtGames (gLifetime.gsGames .~)
-- | Prompt to edit a goalie's lifetime minutes played -- | Prompt to edit a goalie's lifetime minutes played
editGoalieLtMinsPrompt :: Prompt editGoalieLtMinsPrompt :: Prompt
editGoalieLtMinsPrompt = numPrompt "Lifetime minutes played: " $ editGoalieLtMinsPrompt = editNum "Lifetime minutes played: " EGLifetime
modify . editGoalieLtMins (gLifetime.gsMinsPlayed .~)
-- | Prompt to edit a goalie's lifetime goals allowed -- | Prompt to edit a goalie's lifetime goals allowed
editGoalieLtGoalsPrompt :: Prompt editGoalieLtGoalsPrompt :: Prompt
editGoalieLtGoalsPrompt = numPrompt "Lifetime goals allowed: " $ editGoalieLtGoalsPrompt = editNum "Lifetime goals allowed: " EGLifetime
modify . editGoalieLtGoals (gLifetime.gsGoalsAllowed .~)
-- | Prompt to edit a goalie's lifetime wins -- | Prompt to edit a goalie's lifetime wins
editGoalieLtWinsPrompt :: Prompt editGoalieLtWinsPrompt :: Prompt
editGoalieLtWinsPrompt = numPrompt "Lifetime wins: " $ editGoalieLtWinsPrompt = editNum "Lifetime wins: " EGLifetime
modify . editGoalieLtWins (gLifetime.gsWins .~)
-- | Prompt to edit a goalie's lifetime losses -- | Prompt to edit a goalie's lifetime losses
editGoalieLtLossesPrompt :: Prompt editGoalieLtLossesPrompt :: Prompt
editGoalieLtLossesPrompt = numPrompt "Lifetime losses: " $ editGoalieLtLossesPrompt = editNum "Lifetime losses: " EGLifetime
modify . editGoalieLtLosses (gLifetime.gsLosses .~)
-- | Prompt to edit a goalie's lifetime ties -- | Prompt to edit a goalie's lifetime ties
editGoalieLtTiesPrompt :: Prompt editGoalieLtTiesPrompt :: Prompt
editGoalieLtTiesPrompt = numPrompt "Lifetime ties: " $ editGoalieLtTiesPrompt = editNum "Lifetime ties: " EGLifetime
modify . editGoalieLtTies (gLifetime.gsTies .~)
editNum
:: String
-> EditGoalieMode
-> (Int -> Goalie -> Goalie)
-> Prompt
editNum pStr mode f = numPromptWithFallback pStr
(goto mode)
(editGoalie mode . f)
editGoalie :: EditGoalieMode -> (Goalie -> Goalie) -> Action ()
editGoalie mode f =
whenJustM (gets (^.progMode.editGoalieStateL.egsSelectedGoalie)) $ \gid -> do
modify $ database.dbGoalies %~ modifyNth gid f
goto mode
goto :: EditGoalieMode -> Action ()
goto = modify . (progMode.editGoalieStateL.egsMode .~)