From 9e6d41a3ff7480189f7d06299cdb97ef78146352 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Mon, 1 Apr 2024 17:03:49 +0000 Subject: [PATCH] tui: fixed Init handling Don't re-init components on each state change --- pkg/tui/chat.go | 2 -- pkg/tui/tui.go | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/tui/chat.go b/pkg/tui/chat.go index dc9d743..4219835 100644 --- a/pkg/tui/chat.go +++ b/pkg/tui/chat.go @@ -218,8 +218,6 @@ func (m chatModel) Update(msg tea.Msg) (chatModel, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { case msgChangeState: - cmds = append(cmds, m.Init()) - if m.opts.convShortname != "" && m.conversation.ShortName.String != m.opts.convShortname { cmds = append(cmds, m.loadConversation(m.opts.convShortname)) } diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index 1f76852..d12b32a 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -77,9 +77,13 @@ func initialModel(ctx *lmcli.Context, opts Options) model { } func (m model) Init() tea.Cmd { - return func() tea.Msg { - return msgChangeState(m.state) - } + return tea.Batch( + m.conversations.Init(), + m.chat.Init(), + func() tea.Msg { + return msgChangeState(m.state) + }, + ) } func (m *model) handleGlobalInput(msg tea.KeyMsg) (bool, tea.Cmd) {