[WIP] Editing
This commit is contained in:
@ -102,7 +102,7 @@ func (p *ContextPickerPage) View() string {
|
||||
func (p *ContextPickerPage) updateContextCmd() tea.Msg {
|
||||
context := p.form.GetString("context")
|
||||
if context == "(none)" {
|
||||
context = "none"
|
||||
context = ""
|
||||
}
|
||||
return UpdateContextMsg(p.common.TW.GetContext(context))
|
||||
}
|
||||
|
||||
@ -150,6 +150,9 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
p.subpageActive = true
|
||||
p.common.PushPage(p)
|
||||
return p.subpage, nil
|
||||
case key.Matches(msg, p.common.Keymap.Undo):
|
||||
p.common.TW.Undo()
|
||||
return p, p.getTasks()
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,6 +178,8 @@ func (p *ReportPage) View() string {
|
||||
}
|
||||
|
||||
func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
var selected int
|
||||
|
||||
nCols := len(p.activeReport.Columns)
|
||||
columns := make([]table.Column, 0)
|
||||
columnSizes := make([]int, nCols)
|
||||
@ -182,6 +187,10 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
rows := make([]table.Row, len(tasks))
|
||||
|
||||
for i, task := range tasks {
|
||||
if p.selectedTask != nil && task.Uuid == p.selectedTask.Uuid {
|
||||
selected = i
|
||||
}
|
||||
|
||||
row := table.Row{}
|
||||
for i, col := range p.activeReport.Columns {
|
||||
field := task.GetString(col)
|
||||
@ -210,6 +219,10 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
columns = append(columns, table.Column{Title: label, Width: max(columnSizes[i], len(label))})
|
||||
}
|
||||
|
||||
if selected == 0 {
|
||||
selected = p.taskTable.Cursor()
|
||||
}
|
||||
|
||||
p.taskTable = table.New(
|
||||
table.WithColumns(columns),
|
||||
table.WithRows(rows),
|
||||
@ -218,6 +231,12 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
// table.WithWidth(100),
|
||||
)
|
||||
p.taskTable.SetStyles(p.tableStyle)
|
||||
|
||||
if selected < len(p.tasks) {
|
||||
p.taskTable.SetCursor(selected)
|
||||
} else {
|
||||
p.taskTable.SetCursor(len(p.tasks) - 1)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ReportPage) getTasks() tea.Cmd {
|
||||
|
||||
@ -3,6 +3,7 @@ package pages
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"tasksquire/common"
|
||||
"tasksquire/taskwarrior"
|
||||
"time"
|
||||
@ -24,11 +25,17 @@ const (
|
||||
)
|
||||
|
||||
type TaskEditorPage struct {
|
||||
common *common.Common
|
||||
task taskwarrior.Task
|
||||
form *huh.Form
|
||||
mode Mode
|
||||
statusline tea.Model
|
||||
common *common.Common
|
||||
task taskwarrior.Task
|
||||
form *huh.Form
|
||||
mode Mode
|
||||
statusline tea.Model
|
||||
nFields int
|
||||
currentField int
|
||||
|
||||
// TODO: rework support for adding tags and projects
|
||||
additionalTags string
|
||||
additionalProject string
|
||||
}
|
||||
|
||||
type TaskEditorKeys struct {
|
||||
@ -85,11 +92,27 @@ func NewTaskEditorPage(common *common.Common, task taskwarrior.Task) *TaskEditor
|
||||
Title("Project").
|
||||
Value(&p.task.Project),
|
||||
|
||||
huh.NewInput().
|
||||
Title("Project").
|
||||
Value(&p.additionalProject).
|
||||
Validate(func(project string) error {
|
||||
if strings.Contains(project, " ") {
|
||||
return fmt.Errorf("project name cannot contain spaces")
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
Inline(true),
|
||||
|
||||
huh.NewMultiSelect[string]().
|
||||
Options(huh.NewOptions(tagOptions...)...).
|
||||
Title("Tags").
|
||||
Value(&p.task.Tags),
|
||||
|
||||
huh.NewInput().
|
||||
Title("Tags").
|
||||
Value(&p.additionalTags).
|
||||
Inline(true),
|
||||
|
||||
huh.NewInput().
|
||||
Title("Due").
|
||||
Value(&p.task.Due).
|
||||
@ -112,10 +135,13 @@ func NewTaskEditorPage(common *common.Common, task taskwarrior.Task) *TaskEditor
|
||||
WithShowHelp(false).
|
||||
WithShowErrors(true).
|
||||
// use styles from common
|
||||
WithHeight(30).
|
||||
WithHeight(40).
|
||||
WithWidth(50).
|
||||
WithTheme(p.common.Styles.Form)
|
||||
|
||||
p.nFields = 6
|
||||
p.currentField = 0
|
||||
|
||||
p.statusline = NewStatusLine(common, p.mode)
|
||||
|
||||
return p
|
||||
@ -141,7 +167,6 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
p.mode = ModeInsert
|
||||
}
|
||||
}
|
||||
|
||||
switch p.mode {
|
||||
case ModeNormal:
|
||||
switch msg := msg.(type) {
|
||||
@ -208,7 +233,19 @@ func (p *TaskEditorPage) View() string {
|
||||
}
|
||||
|
||||
func (p *TaskEditorPage) updateTasksCmd() tea.Msg {
|
||||
p.common.TW.AddTask(&p.task)
|
||||
if p.task.Project == "(none)" {
|
||||
p.task.Project = ""
|
||||
}
|
||||
if p.task.Priority == "(none)" {
|
||||
p.task.Priority = ""
|
||||
}
|
||||
if p.additionalTags != "" {
|
||||
p.task.Tags = append(p.task.Tags, strings.Split(p.additionalTags, " ")...)
|
||||
}
|
||||
if p.additionalProject != "" {
|
||||
p.task.Project = p.additionalProject
|
||||
}
|
||||
p.common.TW.ImportTask(&p.task)
|
||||
return UpdatedTasksMsg{}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user