From 254d74bdb43a50285018a8f914935c653f7b9955 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 16:05:12 +1300 Subject: [PATCH 1/4] Begin working on new task feature --- bubbletea.go | 57 +++++++++++++++++++++++++++++++++++----------------- model.go | 4 ++-- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/bubbletea.go b/bubbletea.go index 91d5ee5..3d3ea00 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -66,9 +66,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.textinput.Reset() } + case "enter": + if m.addTask { + AddNewTask(m) + m.addTask = false + m.textinput.Reset() + } + // The "enter" key and the spacebar (a literal space) toggle // the selected state for the item that the cursor is pointing at. - case "enter", " ": + case " ": _, ok := m.selected[m.cursor] if ok { delete(m.selected, m.cursor) @@ -84,30 +91,44 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } +func AddNewTask(m model) { + t := todo{ + name: m.textinput.Value(), + done: false, + startdate: 0, + deadline: 0, + priority: 1, + isInbox: true, + } + m.todos = append(m.todos, t) +} + func (m model) View() string { // The header s := "" currentList := []todo{} - // switch m.tab { - // case 0: - // s += "Inbox" - // inboxFilter := func(t todo) bool { return t.isInbox } - // currentList = filter(m.todos, inboxFilter) - // case 1: - // s += "Today" - // case 2: - // s += "Tomorrow" - // case 3: - // s += "Scheduled" - // case 4: - // s += "Anytime" - // } + s += "GOTD\n" - s += "GOTD\n\n" + switch m.tab { + case 0: + s += "Inbox" + inboxFilter := func(t todo) bool { return t.isInbox } + currentList = filter(m.todos, inboxFilter) + case 1: + s += "Today" + case 2: + s += "Tomorrow" + case 3: + s += "Scheduled" + case 4: + s += "Anytime" + } + + s += "\n\n" // Iterate over our choices - for i, choice := range currentList { + for i, value := range currentList { // Is the cursor pointing at this choice? cursor := " " // no cursor @@ -122,7 +143,7 @@ func (m model) View() string { } // Render the row - s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice) + s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value) } // render tab bar diff --git a/model.go b/model.go index fde7083..74730bc 100644 --- a/model.go +++ b/model.go @@ -15,7 +15,7 @@ type todo struct { type model struct { todos []todo // ALL items on the to-do list - list []todo // items currently visible on the list right now + // list []todo // items currently visible on the list right now cursor int // which to-do list item our cursor is pointing at selected map[int]struct{} // which to-do items are selected tab int // which tab is selected @@ -36,7 +36,7 @@ func initialModel() model { // Start empty todos: []todo{}, - list: []todo{}, + // list: []todo{}, // start on today tab // 0: inbox, 1: today, 2: tomorrow, 3: scheduled, 4: anytime -- 2.47.2 From b38412a86efb5453921203c7673953e41e4eff17 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 17:34:05 +1300 Subject: [PATCH 2/4] getting somewhere --- bubbletea.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bubbletea.go b/bubbletea.go index 3d3ea00..fea7c22 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -68,7 +68,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "enter": if m.addTask { - AddNewTask(m) + AddNewTask(&m) m.addTask = false m.textinput.Reset() } @@ -91,7 +91,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func AddNewTask(m model) { +func AddNewTask(m *model) { t := todo{ name: m.textinput.Value(), done: false, @@ -106,15 +106,15 @@ func AddNewTask(m model) { func (m model) View() string { // The header s := "" - currentList := []todo{} + currentList := m.todos s += "GOTD\n" switch m.tab { case 0: s += "Inbox" - inboxFilter := func(t todo) bool { return t.isInbox } - currentList = filter(m.todos, inboxFilter) + // inboxFilter := func(t todo) bool { return t.isInbox } + // currentList = filter(m.todos, inboxFilter) case 1: s += "Today" case 2: -- 2.47.2 From 4d9482f36363bcb93d287fce5b37ad6ca64b82b6 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 17:39:03 +1300 Subject: [PATCH 3/4] better way of checking done status --- bubbletea.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bubbletea.go b/bubbletea.go index fea7c22..3924ed7 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -76,12 +76,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // The "enter" key and the spacebar (a literal space) toggle // the selected state for the item that the cursor is pointing at. case " ": - _, ok := m.selected[m.cursor] - if ok { - delete(m.selected, m.cursor) - } else { - m.selected[m.cursor] = struct{}{} + + if !m.addTask { + if m.todos[m.cursor].done { + m.todos[m.cursor].done = false + } else { + m.todos[m.cursor].done = true + } } + } } @@ -138,8 +141,11 @@ func (m model) View() string { // Is this choice selected? checked := " " // not selected - if _, ok := m.selected[i]; ok { - checked = "x" // selected! + // if _, ok := m.selected[i]; ok { + // checked = "x" // selected! + // } + if value.done { + checked = "x" } // Render the row -- 2.47.2 From 38f4c5e1fa383fd0be6fd1ce99ada6d1e72586e0 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 17:42:32 +1300 Subject: [PATCH 4/4] fix item rendering incorrectly --- bubbletea.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bubbletea.go b/bubbletea.go index 3924ed7..b480353 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -149,7 +149,7 @@ func (m model) View() string { } // Render the row - s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value) + s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value.name) } // render tab bar -- 2.47.2