Skip to content

Commit

Permalink
Merge pull request #57 from aviaviavi/bug/update-cache
Browse files Browse the repository at this point in the history
update cache after edits bug fix
  • Loading branch information
aviaviavi authored Dec 11, 2018
2 parents c33cad2 + a28bab5 commit 9534994
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: toodles
version: 1.0.1
version: 1.0.2
github: "aviaviavi/toodles"
license: MIT
author: "Avi Press"
Expand Down
2 changes: 1 addition & 1 deletion src/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ integer = lexeme $ L.signed space L.decimal
parseAssignee :: Parser String
parseAssignee = many (noneOf [')', '|', '='])

-- TODO(avi|p=3|#cleanup) - fix and type this better
-- TODO (avi|p=3|#cleanup) - fix and type this better
parseDetails :: Text -> (Maybe Text, Maybe Text, [(Text, Text)], [Text])
parseDetails toParse =
let dataTokens = T.splitOn "|" toParse
Expand Down
23 changes: 22 additions & 1 deletion src/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ showRawFile (ToodlesState ref _) eId = do
codeLines)

editTodos :: ToodlesState -> EditTodoRequest -> Handler Text
editTodos (ToodlesState ref _) req = do
editTodos s@(ToodlesState ref _) req = do
storedResults <- liftIO $ readIORef ref
case storedResults of
(Just (TodoListResult r _)) -> do
Expand All @@ -102,6 +102,7 @@ editTodos (ToodlesState ref _) req = do
r
editedFilteredList = filter (willEditTodo req) editedList
_ <- mapM_ recordUpdates editedFilteredList
_ <- updateCache s editedFilteredList
return "{}"
Nothing -> error "no stored todos to edit"
where
Expand Down Expand Up @@ -130,6 +131,26 @@ editTodos (ToodlesState ref _) req = do
recordUpdates :: MonadIO m => TodoEntry -> m ()
recordUpdates t = void $ updateTodoLinesInFile renderTodo t

data UpdateType = UpdateTypeEdit | UpdateTypeDelete deriving (Eq)

updateCache :: MonadIO m => ToodlesState -> [TodoEntry] -> m ()
updateCache (ToodlesState ref _) entries = do
storedResults <- liftIO $ readIORef ref
case storedResults of
(Just (TodoListResult currentCache _)) -> do
let idsToUpdate = map entryId entries
newCache =
TodoListResult
((++ entries)
(filter
(\item -> entryId item `notElem` idsToUpdate)
currentCache))
"edits applied"
_ <-
liftIO $ atomicModifyIORef' ref (const (Just newCache, Just newCache))
return ()
Nothing -> error "no stored todos to update"

renderTodo :: TodoEntry -> [Text]
renderTodo t =
let ext = "." <> getExtension (sourceFile t)
Expand Down
4 changes: 2 additions & 2 deletions toodles.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 95013a4e9f97f67cc56541af010980f8b66d76da59819ff6aef8c68ffdb9bc27
-- hash: eca068224b8e938feec8b371e63c8819e81e6d2030806c1f220e08823596b7f7

name: toodles
version: 1.0.1
version: 1.0.2
synopsis: Manage the TODO entries in your code
description: Toodles scrapes your entire repository for TODO entries and organizes them so you can manage your project directly from the code. View, filter, sort, and edit your TODO\'s with an easy to use web application. When you make changes via toodles, the edits will be applied directly the TODO entries in your code. When you\'re done, commit and push your changes to share them with your team!
category: Project Management
Expand Down

0 comments on commit 9534994

Please sign in to comment.