Add time page
This commit is contained in:
@ -1,14 +1,18 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"tasksquire/common"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type MainPage struct {
|
||||
common *common.Common
|
||||
activePage common.Component
|
||||
|
||||
taskPage common.Component
|
||||
timePage common.Component
|
||||
}
|
||||
|
||||
func NewMainPage(common *common.Common) *MainPage {
|
||||
@ -16,15 +20,16 @@ func NewMainPage(common *common.Common) *MainPage {
|
||||
common: common,
|
||||
}
|
||||
|
||||
m.activePage = NewReportPage(common, common.TW.GetReport(common.TW.GetConfig().Get("uda.tasksquire.report.default")))
|
||||
// m.activePage = NewTaskEditorPage(common, taskwarrior.Task{})
|
||||
m.taskPage = NewReportPage(common, common.TW.GetReport(common.TW.GetConfig().Get("uda.tasksquire.report.default")))
|
||||
m.timePage = NewTimePage(common)
|
||||
|
||||
m.activePage = m.taskPage
|
||||
|
||||
return m
|
||||
|
||||
}
|
||||
|
||||
func (m *MainPage) Init() tea.Cmd {
|
||||
return m.activePage.Init()
|
||||
return tea.Batch(m.taskPage.Init(), m.timePage.Init())
|
||||
}
|
||||
|
||||
func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@ -33,6 +38,19 @@ func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.common.SetSize(msg.Width, msg.Height)
|
||||
case tea.KeyMsg:
|
||||
if key.Matches(msg, m.common.Keymap.Next) {
|
||||
if m.activePage == m.taskPage {
|
||||
m.activePage = m.timePage
|
||||
} else {
|
||||
m.activePage = m.taskPage
|
||||
}
|
||||
// Re-size the new active page just in case
|
||||
m.activePage.SetSize(m.common.Width(), m.common.Height())
|
||||
// Trigger a refresh/init on switch? Maybe not needed if we keep state.
|
||||
// But we might want to refresh data.
|
||||
return m, m.activePage.Init()
|
||||
}
|
||||
}
|
||||
|
||||
activePage, cmd := m.activePage.Update(msg)
|
||||
|
||||
Reference in New Issue
Block a user