diff --git a/src/TaskMachine/Task.hs b/src/TaskMachine/Task.hs index 53e500a..eece150 100644 --- a/src/TaskMachine/Task.hs +++ b/src/TaskMachine/Task.hs @@ -333,19 +333,26 @@ emptyTask = Task Incomplete Nothing Nothing Nothing [] newTask :: Day -> Task newTask day = Task Incomplete Nothing Nothing (Just day) [] +-- Inverted compare for Maybes: Nothing comes after Just +compareMaybe :: Ord a => Maybe a -> Maybe a -> Ordering +compareMaybe Nothing Nothing = EQ +compareMaybe (Just _) Nothing = LT +compareMaybe Nothing (Just _) = GT +compareMaybe (Just x) (Just y) = compare x y + +compareDescription :: Description -> Description -> Ordering +compareDescription = compare `on` formatDescription + compareTasks :: Task -> Task -> Ordering +compareTasks a@(Task (Complete _) _ _ _ _) b@(Task (Complete _) _ _ _ _) = mconcat + [ compare (taskCompletion b) (taskCompletion a) + , compareMaybe (taskPriority a) (taskPriority b) + , compareMaybe (taskDue a) (taskDue b) + , compareDescription (taskDescription a) (taskDescription b) + ] compareTasks a b = mconcat [ compare (taskCompletion a) (taskCompletion b) , compareMaybe (taskPriority a) (taskPriority b) , compareMaybe (taskDue a) (taskDue b) , compareDescription (taskDescription a) (taskDescription b) ] - where - -- Inverted compare for Maybes: Nothing comes after Just - compareMaybe :: Ord a => Maybe a -> Maybe a -> Ordering - compareMaybe Nothing Nothing = EQ - compareMaybe (Just _) Nothing = LT - compareMaybe Nothing (Just _) = GT - compareMaybe (Just x) (Just y) = compare x y - compareDescription :: Description -> Description -> Ordering - compareDescription = compare `on` formatDescription diff --git a/todo.txt b/todo.txt index 555e400..d6c6610 100644 --- a/todo.txt +++ b/todo.txt @@ -12,4 +12,4 @@ x2018-09-30 c2018-09-30 Custom exception messages x2018-10-24 c2018-10-23 Don't crash on parse errors etc. - c2018-10-24 Add "u" - undo and "z" - redo buttons - c2018-10-24 Redo coloring - maybe black-on-white color scheme in-editor? -- c2018-10-24 Reverse ordering of completed tasks - most recent at the top +x2018-10-24 c2018-10-24 Reverse ordering of completed tasks - most recent at the top