Resolved issue #1 (panic on creating task without project). Added more contextual hint message.
This commit is contained in:
@@ -58,7 +58,7 @@ func (pane *ProjectPane) addNewProject() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
statusBar.showForSeconds("[red::]Failed to create Project:"+err.Error(), 5)
|
statusBar.showForSeconds("[red::]Failed to create Project:"+err.Error(), 5)
|
||||||
} else {
|
} else {
|
||||||
statusBar.showForSeconds(fmt.Sprintf("[yellow::]Project %s created. Press n to start adding new tasks.", name), 5)
|
statusBar.showForSeconds(fmt.Sprintf("[yellow::]Project %s created. Press n to start adding new tasks.", name), 10)
|
||||||
pane.projects = append(pane.projects, project)
|
pane.projects = append(pane.projects, project)
|
||||||
pane.addProjectToList(len(pane.projects)-1, true)
|
pane.addProjectToList(len(pane.projects)-1, true)
|
||||||
pane.newProject.SetText("")
|
pane.newProject.SetText("")
|
||||||
|
|||||||
20
app/tasks.go
20
app/tasks.go
@@ -20,6 +20,7 @@ type TaskPane struct {
|
|||||||
newTask *tview.InputField
|
newTask *tview.InputField
|
||||||
projectRepo repository.ProjectRepository
|
projectRepo repository.ProjectRepository
|
||||||
taskRepo repository.TaskRepository
|
taskRepo repository.TaskRepository
|
||||||
|
hint *tview.TextView
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.TaskRepository) *TaskPane {
|
func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.TaskRepository) *TaskPane {
|
||||||
@@ -29,6 +30,7 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
|
|||||||
newTask: makeLightTextInput("+[New Task]"),
|
newTask: makeLightTextInput("+[New Task]"),
|
||||||
projectRepo: projectRepo,
|
projectRepo: projectRepo,
|
||||||
taskRepo: taskRepo,
|
taskRepo: taskRepo,
|
||||||
|
hint: tview.NewTextView().SetTextColor(tcell.ColorYellow).SetTextAlign(tview.AlignCenter),
|
||||||
}
|
}
|
||||||
|
|
||||||
pane.list.SetDoneFunc(func() {
|
pane.list.SetDoneFunc(func() {
|
||||||
@@ -47,11 +49,13 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
|
|||||||
task, err := taskRepo.Create(*projectPane.activeProject, name, "", "", 0)
|
task, err := taskRepo.Create(*projectPane.activeProject, name, "", "", 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statusBar.showForSeconds("[red::]Could not create Task:"+err.Error(), 5)
|
statusBar.showForSeconds("[red::]Could not create Task:"+err.Error(), 5)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pane.tasks = append(pane.tasks, task)
|
pane.tasks = append(pane.tasks, task)
|
||||||
pane.addTaskToList(len(pane.tasks) - 1)
|
pane.addTaskToList(len(pane.tasks) - 1)
|
||||||
pane.newTask.SetText("")
|
pane.newTask.SetText("")
|
||||||
|
statusBar.showForSeconds("[yellow::]Task created. Add another task or press Esc.", 5)
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
app.SetFocus(pane)
|
app.SetFocus(pane)
|
||||||
}
|
}
|
||||||
@@ -60,9 +64,10 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
|
|||||||
|
|
||||||
pane.
|
pane.
|
||||||
AddItem(pane.list, 0, 1, true).
|
AddItem(pane.list, 0, 1, true).
|
||||||
AddItem(pane.newTask, 1, 0, false)
|
AddItem(pane.hint, 0, 1, false)
|
||||||
|
|
||||||
pane.SetBorder(true).SetTitle("[::u]T[::-]asks")
|
pane.SetBorder(true).SetTitle("[::u]T[::-]asks")
|
||||||
|
pane.setHintMessage()
|
||||||
|
|
||||||
return &pane
|
return &pane
|
||||||
}
|
}
|
||||||
@@ -70,6 +75,8 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
|
|||||||
func (pane *TaskPane) ClearList() {
|
func (pane *TaskPane) ClearList() {
|
||||||
pane.list.Clear()
|
pane.list.Clear()
|
||||||
pane.tasks = nil
|
pane.tasks = nil
|
||||||
|
|
||||||
|
pane.RemoveItem(pane.newTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pane *TaskPane) SetList(tasks []model.Task) {
|
func (pane *TaskPane) SetList(tasks []model.Task) {
|
||||||
@@ -105,6 +112,9 @@ func (pane *TaskPane) LoadProjectTasks(project model.Project) {
|
|||||||
} else {
|
} else {
|
||||||
pane.SetList(tasks)
|
pane.SetList(tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pane.RemoveItem(pane.hint)
|
||||||
|
pane.AddItem(pane.newTask, 1, 0, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pane *TaskPane) ActivateTask(idx int) {
|
func (pane *TaskPane) ActivateTask(idx int) {
|
||||||
@@ -127,3 +137,11 @@ func (pane *TaskPane) ClearCompletedTasks() {
|
|||||||
|
|
||||||
statusBar.showForSeconds(fmt.Sprintf("[yellow]%d tasks cleared!", count), 5)
|
statusBar.showForSeconds(fmt.Sprintf("[yellow]%d tasks cleared!", count), 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pane TaskPane) setHintMessage() {
|
||||||
|
if len(projectPane.projects) == 0 {
|
||||||
|
pane.hint.SetText("Welcome to the organized life!\n------------------------------\n Create TaskList/Project at the bottom of Projects pane.\n (Press p,n)")
|
||||||
|
} else {
|
||||||
|
pane.hint.SetText("Select a TaskList/Project to load tasks.\nPress p,n to create new Project.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user