Add details editing
This commit is contained in:
@ -1,6 +1,11 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import tea "github.com/charmbracelet/bubbletea"
|
import (
|
||||||
|
"tasksquire/taskwarrior"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
)
|
||||||
|
|
||||||
type UpdatedTasksMsg struct{}
|
type UpdatedTasksMsg struct{}
|
||||||
|
|
||||||
@ -67,3 +72,13 @@ func changeMode(mode mode) tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type changeModeMsg mode
|
type changeModeMsg mode
|
||||||
|
|
||||||
|
type taskMsg taskwarrior.Tasks
|
||||||
|
|
||||||
|
type tickMsg time.Time
|
||||||
|
|
||||||
|
func doTick() tea.Cmd {
|
||||||
|
return tea.Tick(time.Second, func(t time.Time) tea.Msg {
|
||||||
|
return tickMsg(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@ func (p *ReportPage) SetSize(width int, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReportPage) Init() tea.Cmd {
|
func (p *ReportPage) Init() tea.Cmd {
|
||||||
return p.getTasks()
|
return tea.Batch(p.getTasks(), doTick())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
@ -69,7 +69,11 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
p.SetSize(msg.Width, msg.Height)
|
p.SetSize(msg.Width, msg.Height)
|
||||||
// case BackMsg:
|
// case BackMsg:
|
||||||
case TaskMsg:
|
case tickMsg:
|
||||||
|
cmds = append(cmds, p.getTasks())
|
||||||
|
cmds = append(cmds, doTick())
|
||||||
|
return p, tea.Batch(cmds...)
|
||||||
|
case taskMsg:
|
||||||
p.tasks = taskwarrior.Tasks(msg)
|
p.tasks = taskwarrior.Tasks(msg)
|
||||||
p.populateTaskTable(p.tasks)
|
p.populateTaskTable(p.tasks)
|
||||||
case UpdateReportMsg:
|
case UpdateReportMsg:
|
||||||
@ -99,7 +103,7 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
p.common.PushPage(p)
|
p.common.PushPage(p)
|
||||||
return p.subpage, nil
|
return p.subpage, nil
|
||||||
case key.Matches(msg, p.common.Keymap.Add):
|
case key.Matches(msg, p.common.Keymap.Add):
|
||||||
p.subpage = NewTaskEditorPage(p.common, taskwarrior.Task{})
|
p.subpage = NewTaskEditorPage(p.common, taskwarrior.NewTask())
|
||||||
p.subpage.Init()
|
p.subpage.Init()
|
||||||
p.common.PushPage(p)
|
p.common.PushPage(p)
|
||||||
return p.subpage, nil
|
return p.subpage, nil
|
||||||
@ -212,8 +216,6 @@ func (p *ReportPage) getTasks() tea.Cmd {
|
|||||||
filters = append(filters, "project:"+p.activeProject)
|
filters = append(filters, "project:"+p.activeProject)
|
||||||
}
|
}
|
||||||
tasks := p.common.TW.GetTasks(p.activeReport, filters...)
|
tasks := p.common.TW.GetTasks(p.activeReport, filters...)
|
||||||
return TaskMsg(tasks)
|
return taskMsg(tasks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskMsg taskwarrior.Tasks
|
|
||||||
|
|||||||
@ -11,9 +11,9 @@ import (
|
|||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
|
"github.com/charmbracelet/bubbles/textarea"
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/glamour"
|
|
||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
@ -215,8 +215,11 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
case key.Matches(msg, p.common.Keymap.Ok):
|
case key.Matches(msg, p.common.Keymap.Ok):
|
||||||
model, cmd := p.areas[p.area].Update(msg)
|
model, cmd := p.areas[p.area].Update(msg)
|
||||||
p.areas[p.area] = model.(area)
|
if p.area != 3 {
|
||||||
return p, tea.Batch(cmd, nextField())
|
p.areas[p.area] = model.(area)
|
||||||
|
return p, tea.Batch(cmd, nextField())
|
||||||
|
}
|
||||||
|
return p, cmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,27 +735,38 @@ func (t *timeEdit) View() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type detailsEdit struct {
|
type detailsEdit struct {
|
||||||
com *common.Common
|
com *common.Common
|
||||||
renderer *glamour.TermRenderer
|
vp viewport.Model
|
||||||
vp viewport.Model
|
ta textarea.Model
|
||||||
|
details string
|
||||||
|
// renderer *glamour.TermRenderer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDetailsEdit(com *common.Common, task *taskwarrior.Task) *detailsEdit {
|
func NewDetailsEdit(com *common.Common, task *taskwarrior.Task) *detailsEdit {
|
||||||
renderer, err := glamour.NewTermRenderer(
|
// renderer, err := glamour.NewTermRenderer(
|
||||||
// glamour.WithStandardStyle("light"),
|
// // glamour.WithStandardStyle("light"),
|
||||||
glamour.WithAutoStyle(),
|
// glamour.WithAutoStyle(),
|
||||||
glamour.WithWordWrap(40),
|
// glamour.WithWordWrap(40),
|
||||||
)
|
// )
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
slog.Error(err.Error())
|
// slog.Error(err.Error())
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
vp := viewport.New(40, 30)
|
vp := viewport.New(40, 30)
|
||||||
|
ta := textarea.New()
|
||||||
|
ta.SetWidth(40)
|
||||||
|
ta.SetHeight(30)
|
||||||
|
ta.ShowLineNumbers = false
|
||||||
|
ta.Focus()
|
||||||
|
if task.Udas["details"] != nil {
|
||||||
|
ta.SetValue(task.Udas["details"].(string))
|
||||||
|
}
|
||||||
d := detailsEdit{
|
d := detailsEdit{
|
||||||
com: com,
|
com: com,
|
||||||
renderer: renderer,
|
// renderer: renderer,
|
||||||
vp: vp,
|
vp: vp,
|
||||||
|
ta: ta,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &d
|
return &d
|
||||||
@ -762,7 +776,7 @@ func (d *detailsEdit) SetCursor(c int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *detailsEdit) Init() tea.Cmd {
|
func (d *detailsEdit) Init() tea.Cmd {
|
||||||
return nil
|
return textarea.Blink
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *detailsEdit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (d *detailsEdit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
@ -772,32 +786,34 @@ func (d *detailsEdit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case prevFieldMsg:
|
case prevFieldMsg:
|
||||||
return d, prevArea()
|
return d, prevArea()
|
||||||
default:
|
default:
|
||||||
var cmd tea.Cmd
|
var vpCmd, taCmd tea.Cmd
|
||||||
d.vp, cmd = d.vp.Update(msg)
|
d.vp, vpCmd = d.vp.Update(msg)
|
||||||
return d, cmd
|
d.ta, taCmd = d.ta.Update(msg)
|
||||||
|
return d, tea.Batch(vpCmd, taCmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *detailsEdit) View() string {
|
func (d *detailsEdit) View() string {
|
||||||
dtls := `
|
return d.ta.View()
|
||||||
# Cool Details!
|
// dtls := `
|
||||||
## Things I need
|
// # Cool Details!
|
||||||
- [ ] A thing
|
// ## Things I need
|
||||||
- [x] Done thing
|
// - [ ] A thing
|
||||||
|
// - [x] Done thing
|
||||||
|
|
||||||
## People
|
// ## People
|
||||||
- pe1
|
// - pe1
|
||||||
- pe2
|
// - pe2
|
||||||
`
|
// `
|
||||||
|
|
||||||
details, err := d.renderer.Render(dtls)
|
// details, err := d.renderer.Render(dtls)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
slog.Error(err.Error())
|
// slog.Error(err.Error())
|
||||||
return "Could not parse markdown"
|
// return "Could not parse markdown"
|
||||||
}
|
// }
|
||||||
|
|
||||||
d.vp.SetContent(details)
|
// d.vp.SetContent(details)
|
||||||
return d.vp.View()
|
// return d.vp.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (p *TaskEditorPage) SetSize(width, height int) {
|
// func (p *TaskEditorPage) SetSize(width, height int) {
|
||||||
@ -956,6 +972,10 @@ func (p *TaskEditorPage) updateTasksCmd() tea.Msg {
|
|||||||
// p.common.TW.AddTaskAnnotation(p.task.Uuid, *p.areas[0].(*taskEdit).newAnnotation)
|
// p.common.TW.AddTaskAnnotation(p.task.Uuid, *p.areas[0].(*taskEdit).newAnnotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := p.task.Udas["details"]; ok || p.areas[3].(*detailsEdit).ta.Value() != "" {
|
||||||
|
p.task.Udas["details"] = p.areas[3].(*detailsEdit).ta.Value()
|
||||||
|
}
|
||||||
|
|
||||||
p.common.TW.ImportTask(&p.task)
|
p.common.TW.ImportTask(&p.task)
|
||||||
return UpdatedTasksMsg{}
|
return UpdatedTasksMsg{}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,15 @@ type Task struct {
|
|||||||
Udas map[string]any `json:"-"`
|
Udas map[string]any `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix pointer receiver
|
||||||
|
func NewTask() Task {
|
||||||
|
return Task{
|
||||||
|
Tags: make([]string, 0),
|
||||||
|
Depends: make([]string, 0),
|
||||||
|
Udas: make(map[string]any),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Task) GetString(fieldWFormat string) string {
|
func (t *Task) GetString(fieldWFormat string) string {
|
||||||
field, format, _ := strings.Cut(fieldWFormat, ".")
|
field, format, _ := strings.Cut(fieldWFormat, ".")
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user