added form and db support
This commit is contained in:
parent
5e4bc3ada7
commit
ddb4469501
9 changed files with 504 additions and 48 deletions
28
update.go
28
update.go
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
|
@ -34,17 +35,6 @@ func (m model) updateMonthView(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
} else {
|
||||
m.monthIndex--
|
||||
}
|
||||
|
||||
first := time.Date(m.year, time.Month(m.monthIndex+1), 1, 0, 0, 0, 0, time.UTC)
|
||||
offset := int(first.Weekday())
|
||||
|
||||
m.startOffset = offset
|
||||
m.daysInMonth = time.Date(m.year, time.Month(m.monthIndex+2), 0, 0, 0, 0, 0, time.UTC).Day()
|
||||
|
||||
m.cursorRow = offset / numCols
|
||||
m.cursorCol = offset % numCols
|
||||
|
||||
return m, nil
|
||||
case "d": // Next month
|
||||
if m.monthIndex == 11 {
|
||||
m.monthIndex = 0
|
||||
|
|
@ -52,17 +42,6 @@ func (m model) updateMonthView(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
} else {
|
||||
m.monthIndex++
|
||||
}
|
||||
|
||||
first := time.Date(m.year, time.Month(m.monthIndex+1), 1, 0, 0, 0, 0, time.UTC)
|
||||
offset := int(first.Weekday())
|
||||
|
||||
m.startOffset = offset
|
||||
m.daysInMonth = time.Date(m.year, time.Month(m.monthIndex+2), 0, 0, 0, 0, 0, time.UTC).Day()
|
||||
|
||||
m.cursorRow = offset / numCols
|
||||
m.cursorCol = offset % numCols
|
||||
|
||||
return m, nil
|
||||
case "up":
|
||||
if m.cursorRow > 0 {
|
||||
m.cursorRow--
|
||||
|
|
@ -80,7 +59,6 @@ func (m model) updateMonthView(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.cursorCol++
|
||||
}
|
||||
case "enter":
|
||||
// Calculate selected day based on cursor
|
||||
dayIndex := m.cursorRow*numCols + m.cursorCol
|
||||
if dayIndex >= m.startOffset && dayIndex < m.startOffset+m.daysInMonth {
|
||||
m.selectedDay = dayIndex - m.startOffset + 1
|
||||
|
|
@ -105,6 +83,10 @@ func (m model) updateHourlyView(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "n":
|
||||
showEventForm(context.Background(), func(e EventInput) {
|
||||
_ = SaveEvent(e)
|
||||
})
|
||||
case "esc":
|
||||
m.mode = monthView
|
||||
return m, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue