1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-24 13:26:08 +03:00

Don't do anything if the item itself doesn't exist

This commit is contained in:
Artyom 2016-03-25 00:26:10 +03:00
parent 3d46a83c02
commit ee6ba3e6d6

View File

@ -560,19 +560,20 @@ deleteTrait itemId traitId = do
let itemLens :: Lens' GlobalState Item
itemLens = itemById itemId
let isOurTrait trait = trait^.uid == traitId
item <- use itemLens
-- Determine whether the trait is a pro or a con, and proceed accordingly
case (find isOurTrait (item^.pros), find isOurTrait (item^.cons)) of
-- It's in neither group, which means it was deleted. Do nothing.
(Nothing, Nothing) -> return ()
-- It's a pro
(Just trait, _) -> do
itemLens.pros %= deleteFirst isOurTrait
itemLens.prosDeleted %= (trait:)
-- It's a con
(_, Just trait) -> do
itemLens.cons %= deleteFirst isOurTrait
itemLens.consDeleted %= (trait:)
mbItem <- preuse itemLens
for_ mbItem $ \item -> do
-- Determine whether the trait is a pro or a con, and proceed accordingly
case (find isOurTrait (item^.pros), find isOurTrait (item^.cons)) of
-- It's in neither group, which means it was deleted. Do nothing.
(Nothing, Nothing) -> return ()
-- It's a pro
(Just trait, _) -> do
itemLens.pros %= deleteFirst isOurTrait
itemLens.prosDeleted %= (trait:)
-- It's a con
(_, Just trait) -> do
itemLens.cons %= deleteFirst isOurTrait
itemLens.consDeleted %= (trait:)
-- other methods