[WIP] Add task editing
This commit is contained in:
@ -16,6 +16,7 @@ type TaskEditorPage struct {
|
||||
common *common.Common
|
||||
task taskwarrior.Task
|
||||
form *huh.Form
|
||||
edit bool
|
||||
}
|
||||
|
||||
type TaskEditorKeys struct {
|
||||
@ -32,6 +33,10 @@ func NewTaskEditorPage(common *common.Common, task taskwarrior.Task) *TaskEditor
|
||||
task: task,
|
||||
}
|
||||
|
||||
if task.Uuid != "" {
|
||||
p.edit = true
|
||||
}
|
||||
|
||||
if p.task.Priority == "" {
|
||||
p.task.Priority = "(none)"
|
||||
}
|
||||
@ -118,7 +123,11 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
if p.form.State == huh.StateCompleted {
|
||||
cmds = append(cmds, p.addTaskCmd)
|
||||
if p.edit {
|
||||
cmds = append(cmds, p.editTaskCmd)
|
||||
} else {
|
||||
cmds = append(cmds, p.addTaskCmd)
|
||||
}
|
||||
model, err := p.common.PageStack.Pop()
|
||||
if err != nil {
|
||||
slog.Error("page stack empty")
|
||||
@ -139,8 +148,15 @@ func (p *TaskEditorPage) addTaskCmd() tea.Msg {
|
||||
return AddedTaskMsg{}
|
||||
}
|
||||
|
||||
func (p *TaskEditorPage) editTaskCmd() tea.Msg {
|
||||
p.common.TW.ModifyTask(&p.task)
|
||||
return EditedTaskMsg{}
|
||||
}
|
||||
|
||||
type AddedTaskMsg struct{}
|
||||
|
||||
type EditedTaskMsg struct{}
|
||||
|
||||
// TODO: move this to taskwarrior; add missing date formats
|
||||
func validateDate(s string) error {
|
||||
formats := []string{
|
||||
|
||||
Reference in New Issue
Block a user