mirror of
https://github.com/aelve/guide.git
synced 2024-11-27 10:10:50 +03:00
Delete the group when the item is deleted
This commit is contained in:
parent
9cf876acf1
commit
16021a3d26
19
src/Main.hs
19
src/Main.hs
@ -555,8 +555,25 @@ otherMethods = do
|
|||||||
itemById itemId . cons %= filter ((/= traitId) . view uid)
|
itemById itemId . cons %= filter ((/= traitId) . view uid)
|
||||||
-- Delete item
|
-- Delete item
|
||||||
Spock.post itemVar $ \itemId -> do
|
Spock.post itemVar $ \itemId -> do
|
||||||
|
let category :: Lens' GlobalState Category
|
||||||
|
category = categoryByItem itemId
|
||||||
|
let item :: Lens' GlobalState Item
|
||||||
|
item = itemById itemId
|
||||||
|
-- If the item was the only item in its group, delete the group (and
|
||||||
|
-- make the hue available for new items)
|
||||||
withGlobal $ do
|
withGlobal $ do
|
||||||
categoryByItem itemId . items %= filter ((/= itemId) . view uid)
|
oldGroup <- use (item.group_)
|
||||||
|
case oldGroup of
|
||||||
|
Nothing -> return ()
|
||||||
|
Just g -> do
|
||||||
|
allItems <- use (category.items)
|
||||||
|
let inSameGroup item' = item'^.group_ == Just g
|
||||||
|
isUnique = length (filter inSameGroup allItems) == 1
|
||||||
|
when isUnique $
|
||||||
|
category.groups %= M.delete g
|
||||||
|
-- Delete the item
|
||||||
|
withGlobal $ do
|
||||||
|
category.items %= filter ((/= itemId) . view uid)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
Loading…
Reference in New Issue
Block a user