46 lines
819 B
Go
46 lines
819 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")))
|
|
|
|
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()
|
|
}
|