Add time editing

This commit is contained in:
Martin
2026-02-01 21:46:11 +01:00
parent 72a5c57faa
commit 5cbfc58aa3
3 changed files with 194 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package pages
import (
"time"
"tasksquire/common"
"tasksquire/components/timetable"
"tasksquire/timewarrior"
@ -39,6 +41,8 @@ func (p *TimePage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case intervalsMsg:
p.data = timewarrior.Intervals(msg)
p.populateTable(p.data)
case RefreshIntervalsMsg:
cmds = append(cmds, p.getIntervals())
case tickMsg:
cmds = append(cmds, p.getIntervals())
cmds = append(cmds, doTick())
@ -65,6 +69,20 @@ func (p *TimePage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
p.common.TimeW.DeleteInterval(interval.ID)
return p, tea.Batch(p.getIntervals(), doTick())
}
case key.Matches(msg, p.common.Keymap.Edit):
row := p.intervals.SelectedRow()
if row != nil {
interval := (*timewarrior.Interval)(row)
editor := NewTimeEditorPage(p.common, interval)
p.common.PushPage(p)
return editor, editor.Init()
}
case key.Matches(msg, p.common.Keymap.Add):
interval := timewarrior.NewInterval()
interval.Start = time.Now().UTC().Format("20060102T150405Z")
editor := NewTimeEditorPage(p.common, interval)
p.common.PushPage(p)
return editor, editor.Init()
}
}
@ -75,6 +93,12 @@ func (p *TimePage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return p, tea.Batch(cmds...)
}
type RefreshIntervalsMsg struct{}
func refreshIntervals() tea.Msg {
return RefreshIntervalsMsg{}
}
func (p *TimePage) View() string {
if len(p.data) == 0 {
return p.common.Styles.Base.Render("No intervals found for today")