implemented deleting of goalies

This commit is contained in:
Jonathan Lamothe 2020-03-12 23:37:42 -04:00
parent 1322004d38
commit ded019faac
2 changed files with 38 additions and 1 deletions

View File

@ -23,10 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Control.EditGoalie (editGoalieC) where module Mtlstats.Control.EditGoalie (editGoalieC) where
import Control.Monad.Trans.State (gets, modify)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Lens.Micro ((^.)) import Lens.Micro ((^.), (%~))
import UI.NCurses as C import UI.NCurses as C
import Mtlstats.Actions
import Mtlstats.Handlers
import Mtlstats.Helpers.Goalie import Mtlstats.Helpers.Goalie
import Mtlstats.Menu import Mtlstats.Menu
import Mtlstats.Menu.EditGoalie import Mtlstats.Menu.EditGoalie
@ -52,6 +55,7 @@ editC cb =
EGName -> nameC EGName -> nameC
EGYtd -> ytdMenuC EGYtd -> ytdMenuC
EGLifetime -> lifetimeMenuC EGLifetime -> lifetimeMenuC
EGDelete -> deleteC
EGYtdGames b -> ytdGamesC b EGYtdGames b -> ytdGamesC b
EGYtdMins b -> ytdMinsC b EGYtdMins b -> ytdMinsC b
EGYtdGoals b -> ytdGoalsC b EGYtdGoals b -> ytdGoalsC b
@ -83,6 +87,38 @@ ytdMenuC _ = menuControllerWith header editGoalieYtdMenu
lifetimeMenuC :: Action () -> Controller lifetimeMenuC :: Action () -> Controller
lifetimeMenuC _ = menuControllerWith header editGoalieLtMenu 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 :: Bool -> Action () -> Controller
ytdGamesC = curry $ promptController . ytdGamesC = curry $ promptController .
uncurry editGoalieYtdGamesPrompt uncurry editGoalieYtdGamesPrompt

View File

@ -404,6 +404,7 @@ data EditGoalieMode
| EGName | EGName
| EGYtd | EGYtd
| EGLifetime | EGLifetime
| EGDelete
| EGYtdGames Bool | EGYtdGames Bool
| EGYtdMins Bool | EGYtdMins Bool
| EGYtdGoals Bool | EGYtdGoals Bool