Add New Task from Keybind (#3)
press n to add new task, type in title, then press enter to save Co-authored-by: june <juniper@breadone.xyz> Co-committed-by: june <juniper@breadone.xyz>
This commit is contained in:
parent
ae05b237b4
commit
3acff6618c
73
bubbletea.go
73
bubbletea.go
@ -66,16 +66,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.textinput.Reset()
|
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 "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 "enter", " ":
|
case " ":
|
||||||
_, ok := m.selected[m.cursor]
|
|
||||||
if ok {
|
if !m.addTask {
|
||||||
delete(m.selected, m.cursor)
|
if m.todos[m.cursor].done {
|
||||||
|
m.todos[m.cursor].done = false
|
||||||
} else {
|
} else {
|
||||||
m.selected[m.cursor] = struct{}{}
|
m.todos[m.cursor].done = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,30 +94,44 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, 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 {
|
func (m model) View() string {
|
||||||
// The header
|
// The header
|
||||||
s := ""
|
s := ""
|
||||||
currentList := []todo{}
|
currentList := m.todos
|
||||||
|
|
||||||
// switch m.tab {
|
s += "GOTD\n"
|
||||||
// case 0:
|
|
||||||
// s += "Inbox"
|
switch m.tab {
|
||||||
|
case 0:
|
||||||
|
s += "Inbox"
|
||||||
// inboxFilter := func(t todo) bool { return t.isInbox }
|
// inboxFilter := func(t todo) bool { return t.isInbox }
|
||||||
// currentList = filter(m.todos, inboxFilter)
|
// currentList = filter(m.todos, inboxFilter)
|
||||||
// case 1:
|
case 1:
|
||||||
// s += "Today"
|
s += "Today"
|
||||||
// case 2:
|
case 2:
|
||||||
// s += "Tomorrow"
|
s += "Tomorrow"
|
||||||
// case 3:
|
case 3:
|
||||||
// s += "Scheduled"
|
s += "Scheduled"
|
||||||
// case 4:
|
case 4:
|
||||||
// s += "Anytime"
|
s += "Anytime"
|
||||||
// }
|
}
|
||||||
|
|
||||||
s += "GOTD\n\n"
|
s += "\n\n"
|
||||||
|
|
||||||
// Iterate over our choices
|
// Iterate over our choices
|
||||||
for i, choice := range currentList {
|
for i, value := range currentList {
|
||||||
|
|
||||||
// Is the cursor pointing at this choice?
|
// Is the cursor pointing at this choice?
|
||||||
cursor := " " // no cursor
|
cursor := " " // no cursor
|
||||||
@ -117,12 +141,15 @@ 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, choice)
|
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// render tab bar
|
// render tab bar
|
||||||
|
4
model.go
4
model.go
@ -15,7 +15,7 @@ type todo struct {
|
|||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
todos []todo // ALL items on the to-do list
|
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
|
cursor int // which to-do list item our cursor is pointing at
|
||||||
selected map[int]struct{} // which to-do items are selected
|
selected map[int]struct{} // which to-do items are selected
|
||||||
tab int // which tab is selected
|
tab int // which tab is selected
|
||||||
@ -36,7 +36,7 @@ func initialModel() model {
|
|||||||
// Start empty
|
// Start empty
|
||||||
todos: []todo{},
|
todos: []todo{},
|
||||||
|
|
||||||
list: []todo{},
|
// list: []todo{},
|
||||||
|
|
||||||
// start on today tab
|
// start on today tab
|
||||||
// 0: inbox, 1: today, 2: tomorrow, 3: scheduled, 4: anytime
|
// 0: inbox, 1: today, 2: tomorrow, 3: scheduled, 4: anytime
|
||||||
|
Loading…
x
Reference in New Issue
Block a user