Files
tasksquire/pages/main.go
2024-05-29 19:47:57 +02:00

47 lines
884 B
Go

package pages
import (
tea "github.com/charmbracelet/bubbletea"
"tasksquire/common"
)
type MainPage struct {
common *common.Common
activePage common.Component
}
func NewMainPage(common *common.Common) *MainPage {
m := &MainPage{
common: common,
}
m.activePage = NewReportPage(common, common.TW.GetReport(common.TW.GetConfig().Get("uda.tasksquire.report.default")))
// m.activePage = NewTaskEditorPage(common, taskwarrior.Task{})
return m
}
func (m *MainPage) Init() tea.Cmd {
return m.activePage.Init()
}
func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.common.SetSize(msg.Width, msg.Height)
}
activePage, cmd := m.activePage.Update(msg)
m.activePage = activePage.(common.Component)
return m, cmd
}
func (m *MainPage) View() string {
return m.activePage.View()
}