Skip to content

Commit 9534994

Browse files
authored
Merge pull request #57 from aviaviavi/bug/update-cache
update cache after edits bug fix
2 parents c33cad2 + a28bab5 commit 9534994

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: toodles
2-
version: 1.0.1
2+
version: 1.0.2
33
github: "aviaviavi/toodles"
44
license: MIT
55
author: "Avi Press"

src/Parse.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ integer = lexeme $ L.signed space L.decimal
7777
parseAssignee :: Parser String
7878
parseAssignee = many (noneOf [')', '|', '='])
7979

80-
-- TODO(avi|p=3|#cleanup) - fix and type this better
80+
-- TODO (avi|p=3|#cleanup) - fix and type this better
8181
parseDetails :: Text -> (Maybe Text, Maybe Text, [(Text, Text)], [Text])
8282
parseDetails toParse =
8383
let dataTokens = T.splitOn "|" toParse

src/Server.hs

+22-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ showRawFile (ToodlesState ref _) eId = do
8989
codeLines)
9090

9191
editTodos :: ToodlesState -> EditTodoRequest -> Handler Text
92-
editTodos (ToodlesState ref _) req = do
92+
editTodos s@(ToodlesState ref _) req = do
9393
storedResults <- liftIO $ readIORef ref
9494
case storedResults of
9595
(Just (TodoListResult r _)) -> do
@@ -102,6 +102,7 @@ editTodos (ToodlesState ref _) req = do
102102
r
103103
editedFilteredList = filter (willEditTodo req) editedList
104104
_ <- mapM_ recordUpdates editedFilteredList
105+
_ <- updateCache s editedFilteredList
105106
return "{}"
106107
Nothing -> error "no stored todos to edit"
107108
where
@@ -130,6 +131,26 @@ editTodos (ToodlesState ref _) req = do
130131
recordUpdates :: MonadIO m => TodoEntry -> m ()
131132
recordUpdates t = void $ updateTodoLinesInFile renderTodo t
132133

134+
data UpdateType = UpdateTypeEdit | UpdateTypeDelete deriving (Eq)
135+
136+
updateCache :: MonadIO m => ToodlesState -> [TodoEntry] -> m ()
137+
updateCache (ToodlesState ref _) entries = do
138+
storedResults <- liftIO $ readIORef ref
139+
case storedResults of
140+
(Just (TodoListResult currentCache _)) -> do
141+
let idsToUpdate = map entryId entries
142+
newCache =
143+
TodoListResult
144+
((++ entries)
145+
(filter
146+
(\item -> entryId item `notElem` idsToUpdate)
147+
currentCache))
148+
"edits applied"
149+
_ <-
150+
liftIO $ atomicModifyIORef' ref (const (Just newCache, Just newCache))
151+
return ()
152+
Nothing -> error "no stored todos to update"
153+
133154
renderTodo :: TodoEntry -> [Text]
134155
renderTodo t =
135156
let ext = "." <> getExtension (sourceFile t)

toodles.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 95013a4e9f97f67cc56541af010980f8b66d76da59819ff6aef8c68ffdb9bc27
7+
-- hash: eca068224b8e938feec8b371e63c8819e81e6d2030806c1f220e08823596b7f7
88

99
name: toodles
10-
version: 1.0.1
10+
version: 1.0.2
1111
synopsis: Manage the TODO entries in your code
1212
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!
1313
category: Project Management

0 commit comments

Comments
 (0)