Compare commits

..

1 Commits

Author SHA1 Message Date
june
254d74bdb4 Begin working on new task feature 2025-03-10 16:05:12 +13:00
2 changed files with 19 additions and 42 deletions

View File

@@ -68,7 +68,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter": case "enter":
if m.addTask { if m.addTask {
AddNewTask(&m) AddNewTask(m)
m.addTask = false m.addTask = false
m.textinput.Reset() m.textinput.Reset()
} }
@@ -76,16 +76,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// The "enter" key and the spacebar (a literal space) toggle // The "enter" key and the spacebar (a literal space) toggle
// the selected state for the item that the cursor is pointing at. // the selected state for the item that the cursor is pointing at.
case " ": case " ":
_, ok := m.selected[m.cursor]
if !m.addTask { if ok {
if m.todos[m.cursor].done { delete(m.selected, m.cursor)
m.todos[m.cursor].done = false
} else { } else {
m.todos[m.cursor].done = true m.selected[m.cursor] = struct{}{}
} }
} }
}
} }
@@ -94,7 +91,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd return m, cmd
} }
func AddNewTask(m *model) { func AddNewTask(m model) {
t := todo{ t := todo{
name: m.textinput.Value(), name: m.textinput.Value(),
done: false, done: false,
@@ -111,32 +108,24 @@ func (m model) View() string {
s := "" s := ""
currentList := []todo{} currentList := []todo{}
s += "GOTD\n\n" s += "GOTD\n"
switch m.tab { switch m.tab {
case 0: case 0:
// s += "Inbox" s += "Inbox"
taskFilter := func(t todo) bool { return t.isInbox } inboxFilter := func(t todo) bool { return t.isInbox }
currentList = filter(m.todos, taskFilter) currentList = filter(m.todos, inboxFilter)
case 1: 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: 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: case 3:
// s += "Scheduled" s += "Scheduled"
taskFilter := func(t todo) bool { return t.startdate != -1 }
currentList = filter(m.todos, taskFilter)
case 4: case 4:
// s += "Anytime" s += "Anytime"
taskFilter := func(t todo) bool { return t.startdate == -1 }
currentList = filter(m.todos, taskFilter)
} }
s += "\n\n"
// Iterate over our choices // Iterate over our choices
for i, value := range currentList { for i, value := range currentList {
@@ -149,19 +138,14 @@ func (m model) View() string {
// Is this choice selected? // Is this choice selected?
checked := " " // not selected checked := " " // not selected
// if _, ok := m.selected[i]; ok { if _, ok := m.selected[i]; ok {
// checked = "x" // selected! checked = "x" // selected!
// }
if value.done {
checked = "x"
} }
// Render the row // Render the row
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value.name) s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value)
} }
s += "\n\n"
// render tab bar // render tab bar
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} { for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
if i == m.tab { if i == m.tab {

View File

@@ -2,7 +2,6 @@ package main
import ( import (
"os" "os"
"time"
"os/exec" "os/exec"
"runtime" "runtime"
) )
@@ -16,12 +15,6 @@ func filter[T any](ss []T, test func(T) bool) (ret []T) {
return 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() { func clearTerminal() {
var cmd *exec.Cmd var cmd *exec.Cmd
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {