Tasks should be filtered into their specific areas #5

Merged
breadone merged 2 commits from #1 into main 2025-03-10 18:42:06 +13:00
2 changed files with 25 additions and 10 deletions
Showing only changes of commit fe915f69af - Show all commits

View File

@ -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 {

View File

@ -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" {