Compare commits

...

2 Commits

Author SHA1 Message Date
june
4d9482f363
better way of checking done status 2025-03-10 17:39:03 +13:00
june
b38412a86e
getting somewhere 2025-03-10 17:34:05 +13:00

View File

@ -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()
}
@ -76,13 +76,16 @@ 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)
if !m.addTask {
if m.todos[m.cursor].done {
m.todos[m.cursor].done = false
} else {
m.selected[m.cursor] = struct{}{}
m.todos[m.cursor].done = true
}
}
}
}
@ -91,7 +94,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 +109,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:
@ -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