From fe915f69af90590f009fb31472e51694e0fc89ec Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 18:39:10 +1300 Subject: [PATCH 1/2] Add contextual list rendering depending which tab is highlighted --- bubbletea.go | 28 ++++++++++++++++++---------- helper.go | 7 +++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/bubbletea.go b/bubbletea.go index b480353..41470cc 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -109,26 +109,32 @@ func AddNewTask(m *model) { func (m model) View() string { // The header s := "" - currentList := m.todos + currentList := []todo{} - 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) + // s += "Inbox" + taskFilter := func(t todo) bool { return t.isInbox } + currentList = filter(m.todos, taskFilter) case 1: - s += "Today" + // s += "Today" + taskFilter := func(t todo) bool { return t.startdate == int(midnightToUnix()) || t.deadline == int(midnightToUnix()) } + currentList = filter(m.todos, taskFilter) case 2: - s += "Tomorrow" + // s += "Tomorrow" + // 86400 seconds in 24h, add it on to today's midnight for tomorrow's midnight + taskFilter := func(t todo) bool { return t.startdate == int(midnightToUnix()) + 86400 || t.deadline == int(midnightToUnix()) + 86400} + currentList = filter(m.todos, taskFilter) case 3: - s += "Scheduled" + // s += "Scheduled" case 4: - s += "Anytime" + // s += "Anytime" + taskFilter := func(t todo) bool { return t.startdate == -1 || t.deadline == -1 } + currentList = filter(m.todos, taskFilter) } - s += "\n\n" // Iterate over our choices for i, value := range currentList { @@ -152,6 +158,8 @@ func (m model) View() string { s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value.name) } + s += "\n\n" + // render tab bar for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} { if i == m.tab { diff --git a/helper.go b/helper.go index eaccebc..8b7222b 100644 --- a/helper.go +++ b/helper.go @@ -2,6 +2,7 @@ package main import ( "os" + "time" "os/exec" "runtime" ) @@ -15,6 +16,12 @@ func filter[T any](ss []T, test func(T) bool) (ret []T) { return } +func midnightToUnix() int64 { + now := time.Now() + midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + return midnight.Unix() +} + func clearTerminal() { var cmd *exec.Cmd if runtime.GOOS == "windows" { -- 2.47.2 From e49b64b26b86736f0b5f97e03c3a47c8fd040874 Mon Sep 17 00:00:00 2001 From: june Date: Mon, 10 Mar 2025 18:40:53 +1300 Subject: [PATCH 2/2] Added filter for scheduled tab and changed anytime tab --- bubbletea.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bubbletea.go b/bubbletea.go index 41470cc..3e7f3ff 100644 --- a/bubbletea.go +++ b/bubbletea.go @@ -129,9 +129,11 @@ func (m model) View() string { currentList = filter(m.todos, taskFilter) case 3: // s += "Scheduled" + taskFilter := func(t todo) bool { return t.startdate != -1 } + currentList = filter(m.todos, taskFilter) case 4: // s += "Anytime" - taskFilter := func(t todo) bool { return t.startdate == -1 || t.deadline == -1 } + taskFilter := func(t todo) bool { return t.startdate == -1 } currentList = filter(m.todos, taskFilter) } -- 2.47.2