Skip to content

Commit

Permalink
feat: adds ClearDate in DUE mode
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Aug 29, 2019
1 parent d65f28e commit cdc533d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 13 deletions.
8 changes: 4 additions & 4 deletions roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@

## In Progress

- Remove date
* [x] NORMAL mode
* [x] DETAIL mode
* [ ] DUE mode
- Some way to just see tasks with due dates
* [x] Sort by date
* [x] Scrollable
Expand Down Expand Up @@ -310,3 +306,7 @@
- Remove `~` style sub-task complete parsing
- MoveTo shouldn't show if nothing selected
- Deleting a list can screw up current position
- Remove date
* [x] NORMAL mode
* [x] DETAIL mode
* [x] DUE mode
2 changes: 2 additions & 0 deletions src/Data/Taskell/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

module Data.Taskell.List
( List
, Update
, title
, tasks
, create
, empty
, due
, clearDue
, new
, count
, newAt
Expand Down
5 changes: 4 additions & 1 deletion src/Data/Taskell/List/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Control.Lens (element, makeLenses, (%%~), (%~), (&), (.~), (^.), (^?))
import Data.Sequence as S (adjust', deleteAt, insertAt, update, (|>))

import qualified Data.Taskell.Seq as S
import qualified Data.Taskell.Task as T (Task, Update, blank, contains, due, duplicate)
import qualified Data.Taskell.Task as T (Task, Update, blank, clearDue, contains, due, duplicate)
import Types (TaskIndex (TaskIndex))

data List = List
Expand Down Expand Up @@ -42,6 +42,9 @@ due list = catMaybes (filt S.<#> (list ^. tasks))
where
filt int task = const (TaskIndex int, task) <$> task ^. T.due

clearDue :: TaskIndex -> Update
clearDue (TaskIndex int) = updateFn int T.clearDue

newAt :: Int -> Update
newAt idx = tasks %~ S.insertAt idx T.blank

Expand Down
1 change: 1 addition & 0 deletions src/Data/Taskell/Lists.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Data.Taskell.Lists
, updateLists
, count
, due
, clearDue
, get
, changeList
, newList
Expand Down
11 changes: 9 additions & 2 deletions src/Data/Taskell/Lists/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module Data.Taskell.Lists.Internal where
import ClassyPrelude

import Control.Lens ((^.))
import Data.Sequence as S (deleteAt, update, (!?), (|>))
import Data.Sequence as S (adjust', deleteAt, update, (!?), (|>))

import qualified Data.Taskell.List as L (List, append, count, due, empty, extract, searchFor)
import qualified Data.Taskell.List as L (List, Update, append, clearDue, count, due, empty, extract,
searchFor)
import qualified Data.Taskell.Seq as S
import qualified Data.Taskell.Task as T (Task, due)
import Types (ListIndex (ListIndex), Pointer, TaskIndex (TaskIndex))
Expand All @@ -33,6 +34,12 @@ due lists = sortOn ((^. T.due) . snd) dues
format x lst = (\(y, t) -> ((ListIndex x, y), t)) <$> L.due lst
dues = concat $ format S.<#> lists

clearDue :: Pointer -> Update
clearDue (idx, tsk) = updateFn idx (L.clearDue tsk)

updateFn :: ListIndex -> L.Update -> Update
updateFn (ListIndex idx) fn = adjust' fn idx

get :: Lists -> Int -> Maybe L.List
get = (!?)

Expand Down
1 change: 1 addition & 0 deletions src/Data/Taskell/Task.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Data.Taskell.Task
, setDescription
, appendDescription
, setDue
, clearDue
, getSubtask
, addSubtask
, hasSubtasks
Expand Down
3 changes: 3 additions & 0 deletions src/Data/Taskell/Task/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ setDue date task =
Just day -> task & due .~ Just day
Nothing -> task

clearDue :: Update
clearDue task = task & due .~ Nothing

getSubtask :: Int -> Task -> Maybe ST.Subtask
getSubtask idx = (^? subtasks . ix idx)

Expand Down
11 changes: 8 additions & 3 deletions src/Events/Actions/Modal/Due.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ module Events.Actions.Modal.Due
import ClassyPrelude

import Events.Actions.Types as A (ActionType (..))
import Events.State (normalMode)
import Events.State (normalMode, store, write)
import Events.State.Modal.Detail (showDetail)
import Events.State.Modal.Due (goto, next, previous)
import Events.State.Modal.Due (clearDate, goto, next, previous)
import Events.State.Types (Stateful)
import Graphics.Vty.Input.Events (Event (EvKey))
import IO.Keyboard.Types (Actions)

events :: Actions
events = [(A.Previous, previous), (A.Next, next), (A.Detail, (showDetail =<<) . goto)]
events =
[ (A.Previous, previous)
, (A.Next, next)
, (A.Detail, (showDetail =<<) . goto)
, (A.ClearDate, (write =<<) . (clearDate =<<) . store)
]

event :: Event -> Stateful
event (EvKey _ _) = normalMode
Expand Down
4 changes: 2 additions & 2 deletions src/Events/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Data.Char (digitToInt, ord)
import qualified Data.Taskell.List as L (List, deleteTask, duplicate, getTask, move, nearest, new,
newAt, nextTask, prevTask, title, update)
import qualified Data.Taskell.Lists as Lists
import Data.Taskell.Task (Task, due, isBlank, name)
import Data.Taskell.Task (Task, isBlank, name)
import Types

import Events.State.Types
Expand Down Expand Up @@ -191,7 +191,7 @@ clearItem :: Stateful
clearItem = setCurrentTaskText ""

clearDate :: Stateful
clearDate state = flip setCurrentTask state =<< (due .~ Nothing) <$> getCurrentTask state
clearDate state = pure $ state & lists .~ Lists.clearDue (state ^. current) (state ^. lists)

bottom :: Stateful
bottom = pure . selectLast
Expand Down
14 changes: 13 additions & 1 deletion src/Events/State/Modal/Due.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Events.State.Modal.Due
( showDue
, clearDate
, previous
, next
, goto
Expand All @@ -12,7 +13,7 @@ import ClassyPrelude
import Control.Lens ((&), (.~), (^.))
import Data.Sequence ((!?))

import qualified Data.Taskell.Lists as L (due)
import qualified Data.Taskell.Lists as L (clearDue, due)
import Events.State.Types (Stateful, current, lists, mode)
import Events.State.Types.Mode (ModalType (Due), Mode (..))

Expand Down Expand Up @@ -52,3 +53,14 @@ goto state =
Just (pointer, _) -> pure $ state & current .~ pointer
Nothing -> Nothing
_ -> pure state

clearDate :: Stateful
clearDate state =
case state ^. mode of
Modal (Due due cur) ->
case due !? cur of
Just (pointer, _) -> do
let cleared = state & lists .~ L.clearDue pointer (state ^. lists)
pure $ cleared & mode .~ Modal (Due (L.due (cleared ^. lists)) 0)
Nothing -> Nothing
_ -> pure state

0 comments on commit cdc533d

Please sign in to comment.