summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 22:51:49 +0300
committerGitHub <noreply@github.com>2025-06-20 22:51:49 +0300
commitb2a1534b2dd5a0ee699499b0e24c17ca511c95cf (patch)
tree8bac7578627cbfdbbd697ca2ac38881f4075c95e /internal
parent7f9b5545a48866390f6a8d7ab7b7bf93215b721f (diff)
parent8802613e9eb295124d7e42fee0393a690afaa2c1 (diff)
Merge pull request #63 from snonux/codex/change-due-date-hotkey-to-open-date-picker
Add date picker for due date hotkey
Diffstat (limited to 'internal')
-rw-r--r--internal/ui/table.go32
-rw-r--r--internal/ui/table_test.go7
2 files changed, 24 insertions, 15 deletions
diff --git a/internal/ui/table.go b/internal/ui/table.go
index 530e813..0fafe02 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -42,7 +42,7 @@ type Model struct {
dueEditing bool
dueID int
- dueInput textinput.Model
+ dueDate time.Time
searching bool
searchInput textinput.Model
@@ -79,8 +79,7 @@ func New(filters []string) (Model, error) {
m := Model{filters: filters}
m.annotateInput = textinput.New()
m.annotateInput.Prompt = "annotation: "
- m.dueInput = textinput.New()
- m.dueInput.Prompt = "due: "
+ m.dueDate = time.Now()
m.searchInput = textinput.New()
m.searchInput.Prompt = "search: "
@@ -208,19 +207,25 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.dueEditing {
switch msg.Type {
case tea.KeyEnter:
- task.SetDueDate(m.dueID, m.dueInput.Value())
+ task.SetDueDate(m.dueID, m.dueDate.Format("2006-01-02"))
m.dueEditing = false
- m.dueInput.Blur()
m.reload()
return m, nil
case tea.KeyEsc:
m.dueEditing = false
- m.dueInput.Blur()
return m, nil
}
- var cmd tea.Cmd
- m.dueInput, cmd = m.dueInput.Update(msg)
- return m, cmd
+ switch msg.String() {
+ case "h", "left":
+ m.dueDate = m.dueDate.AddDate(0, 0, -1)
+ case "l", "right":
+ m.dueDate = m.dueDate.AddDate(0, 0, 1)
+ case "k", "up":
+ m.dueDate = m.dueDate.AddDate(0, 0, -7)
+ case "j", "down":
+ m.dueDate = m.dueDate.AddDate(0, 0, 7)
+ }
+ return m, nil
}
if m.prioritySelecting {
switch msg.Type {
@@ -341,8 +346,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if id, err := strconv.Atoi(idStr); err == nil {
m.dueID = id
m.dueEditing = true
- m.dueInput.SetValue("")
- m.dueInput.Focus()
+ m.dueDate = time.Now()
return m, nil
}
}
@@ -456,7 +460,7 @@ func (m Model) View() string {
if m.dueEditing {
view = lipgloss.JoinVertical(lipgloss.Left,
view,
- m.dueInput.View(),
+ m.dueView(),
)
}
if m.prioritySelecting {
@@ -561,6 +565,10 @@ func formatPriority(p string) string {
return style.Render(p)
}
+func (m Model) dueView() string {
+ return fmt.Sprintf("due: %s", m.dueDate.Format("2006-01-02"))
+}
+
func (m Model) priorityView() string {
var parts []string
for i, p := range priorityOptions {
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index d7ee19d..77ee3f3 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -263,8 +263,8 @@ func TestDueDateHotkey(t *testing.T) {
mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}})
m = mv.(Model)
- for _, r := range "2024-12-31" {
- mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
+ for i := 0; i < 3; i++ {
+ mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRight})
m = mv.(Model)
}
mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
@@ -275,7 +275,8 @@ func TestDueDateHotkey(t *testing.T) {
t.Fatalf("read due: %v", err)
}
- if strings.TrimSpace(string(data)) != "1 modify due:2024-12-31" {
+ want := "1 modify due:" + time.Now().AddDate(0, 0, 3).Format("2006-01-02")
+ if strings.TrimSpace(string(data)) != want {
t.Fatalf("due not set: %q", data)
}
}