Add New Task from Keybind #3

Merged
breadone merged 4 commits from 2-new-task into main 2025-03-10 17:50:38 +13:00
2 changed files with 41 additions and 20 deletions
Showing only changes of commit 254d74bdb4 - Show all commits

View File

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

View File

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