From ded019faac196c59f5b4f7b5fcecbf2a720fc3d1 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 12 Mar 2020 23:37:42 -0400 Subject: [PATCH] implemented deleting of goalies --- src/Mtlstats/Control/EditGoalie.hs | 38 +++++++++++++++++++++++++++++- src/Mtlstats/Types.hs | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/EditGoalie.hs b/src/Mtlstats/Control/EditGoalie.hs index 595b35a..3bca300 100644 --- a/src/Mtlstats/Control/EditGoalie.hs +++ b/src/Mtlstats/Control/EditGoalie.hs @@ -23,10 +23,13 @@ along with this program. If not, see . module Mtlstats.Control.EditGoalie (editGoalieC) where +import Control.Monad.Trans.State (gets, modify) import Data.Maybe (fromMaybe) -import Lens.Micro ((^.)) +import Lens.Micro ((^.), (%~)) import UI.NCurses as C +import Mtlstats.Actions +import Mtlstats.Handlers import Mtlstats.Helpers.Goalie import Mtlstats.Menu import Mtlstats.Menu.EditGoalie @@ -52,6 +55,7 @@ editC cb = EGName -> nameC EGYtd -> ytdMenuC EGLifetime -> lifetimeMenuC + EGDelete -> deleteC EGYtdGames b -> ytdGamesC b EGYtdMins b -> ytdMinsC b EGYtdGoals b -> ytdGoalsC b @@ -83,6 +87,38 @@ ytdMenuC _ = menuControllerWith header editGoalieYtdMenu lifetimeMenuC :: Action () -> Controller lifetimeMenuC _ = menuControllerWith header editGoalieLtMenu +deleteC :: Action () -> Controller +deleteC _ = Controller + + { drawController = \s -> do + + C.drawString $ let + + hdr = fromMaybe [] $ do + gid <- s^.progMode.editGoalieStateL.egsSelectedGoalie + goalie <- nth gid $ s^.database.dbGoalies + Just $ "Goalie: " ++ goalieDetails goalie ++ "\n\n" + + in hdr ++ "Are you sure you want to delete this goalie? (Y/N)" + + return C.CursorInvisible + + , handleController = \e -> do + + case ynHandler e of + + Just True -> do + gets (^.progMode.editGoalieStateL.egsSelectedGoalie) >>= mapM_ + (\gid -> modify $ database.dbGoalies %~ dropNth gid) + modify editGoalie + + Just False -> modify editGoalie + Nothing -> return () + + return True + + } + ytdGamesC :: Bool -> Action () -> Controller ytdGamesC = curry $ promptController . uncurry editGoalieYtdGamesPrompt diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 4c3c9a4..b64f46a 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -404,6 +404,7 @@ data EditGoalieMode | EGName | EGYtd | EGLifetime + | EGDelete | EGYtdGames Bool | EGYtdMins Bool | EGYtdGoals Bool