tui: fixed Init handling

Don't re-init components on each state change
This commit is contained in:
Matt Low 2024-04-01 17:03:49 +00:00
parent 39cd4227c6
commit 9e6d41a3ff
2 changed files with 7 additions and 5 deletions

View File

@ -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))
}

View File

@ -77,9 +77,13 @@ func initialModel(ctx *lmcli.Context, opts Options) model {
}
func (m model) Init() tea.Cmd {
return func() tea.Msg {
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) {