diff --git a/app/Main.hs b/app/Main.hs index 493fc17..e67a0d9 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -10,4 +10,5 @@ import TaskMachine.UI main :: IO() main = do o <- parseOptions - void $ B.defaultMain myApp (startUIState o) + state <- loadTasks $ startUIState o + void $ B.defaultMain myApp state diff --git a/src/TaskMachine/UI.hs b/src/TaskMachine/UI.hs index 2609c41..9fddcc5 100644 --- a/src/TaskMachine/UI.hs +++ b/src/TaskMachine/UI.hs @@ -1,6 +1,7 @@ module TaskMachine.UI ( myApp , startUIState + , loadTasks ) where import qualified Brick as B @@ -9,15 +10,20 @@ import qualified Brick.Themes as B import qualified Data.Vector as V import qualified Graphics.Vty.Input.Events as VTY +import TaskMachine.LTask import TaskMachine.Options -import TaskMachine.UI.NewTask import TaskMachine.UI.Popup import TaskMachine.UI.TaskList -import TaskMachine.UI.TopBar import TaskMachine.UI.Types {- Rendering -} +placeholderTopBar :: B.Widget n +placeholderTopBar = B.str "Prune | Reload | Search: " B.<+> B.vLimit 1 (B.fill '_') + +placeholderNewTask :: B.Widget RName +placeholderNewTask = B.str "New: " B.<+> B.vLimit 1 (B.fill '_') + drawBaseLayer :: UIState -> B.Widget RName drawBaseLayer s = B.vBox [placeholderTopBar, renderTaskList True (tasks s), placeholderNewTask] @@ -25,6 +31,17 @@ drawUIState :: UIState -> [B.Widget RName] drawUIState s@UIState{errorPopup=Just p} = [renderPopupOk p, drawBaseLayer s] drawUIState s = [drawBaseLayer s] +{- Actions -} + +loadTasks :: UIState -> IO UIState +loadTasks s = do + let file = oTodofile $ options s + result <- loadLTasks file + case result of + -- TODO: Improve error handling when loading files + Left errorMessage -> pure s{errorPopup=Just $ popupOk "Error loading tasks" errorMessage} + Right ltasks -> pure s{tasks=taskList RTaskList ltasks} + {- Updating the state -} rootBehavior :: UIState -> VTY.Event -> NewState diff --git a/src/TaskMachine/UI/NewTask.hs b/src/TaskMachine/UI/NewTask.hs deleted file mode 100644 index ca119ff..0000000 --- a/src/TaskMachine/UI/NewTask.hs +++ /dev/null @@ -1,8 +0,0 @@ -module TaskMachine.UI.NewTask where - -import qualified Brick as B - -import TaskMachine.UI.Types - -placeholderNewTask :: B.Widget RName -placeholderNewTask = B.str "New: " B.<+> B.vLimit 1 (B.fill '_') diff --git a/src/TaskMachine/UI/TopBar.hs b/src/TaskMachine/UI/TopBar.hs deleted file mode 100644 index 16c708f..0000000 --- a/src/TaskMachine/UI/TopBar.hs +++ /dev/null @@ -1,6 +0,0 @@ -module TaskMachine.UI.TopBar where - -import qualified Brick as B - -placeholderTopBar :: B.Widget n -placeholderTopBar = B.str "Prune | Reload | Search: " B.<+> B.vLimit 1 (B.fill '_') diff --git a/todo.txt b/todo.txt index f37e717..ac537ee 100644 --- a/todo.txt +++ b/todo.txt @@ -3,5 +3,5 @@ - c2018-09-18 Offer "retry" or "quit" +dialogue - syntax error in todo file - c2018-09-18 Offer to clean up file when loading (adding creation/completion dates) - c2018-09-18 Purge - move completed tasks to a separate file -- c2018-09-18 Quit using Esc or q - c2018-09-18 Sort tasks by completion, priority, due date, description +x2018-09-27 c2018-09-18 Quit using Esc or q