feat: move init to tea.msg

This commit is contained in:
Anish Lakhwara 2024-05-25 03:20:21 -07:00
parent 98482784bc
commit 30f6f2b7b4

11
main.go
View file

@ -63,7 +63,7 @@ func loadTasks() tea.Msg {
Foreground(lipgloss.Color("0")).
Background(lipgloss.Color("120"))
t.SetStyles(s)
return t
return LoadedTasksMsg{t}
}
type editorFinishedMsg struct{ err error }
@ -104,9 +104,9 @@ func (m model) openEditor() tea.Cmd {
})
}
// TODO
// This is where the data should be loaded...
func (m model) Init() tea.Cmd { return nil }
func (m model) Init() tea.Cmd {
return loadTasks
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
@ -122,6 +122,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
//top, right, bottom, left := baseStyle.GetMargin()
m.taskList.SetWidth(msg.Width - 5)
m.taskList.SetHeight(msg.Height - 5)
case LoadedTasksMsg:
m.taskList = msg.TaskList
}
m.taskList, cmd = m.taskList.Update(msg)
return m, cmd
@ -133,7 +135,6 @@ func (m model) View() string {
func main() {
var m model
m.taskList = CreateTable()
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)