refactor(ui/chat): batch logout event commands

This commit is contained in:
ayn2op 2026-03-04 01:21:03 -05:00
parent 5afee6e9fa
commit 1583f822e3
2 changed files with 22 additions and 5 deletions

View file

@ -1,6 +1,11 @@
package chat
import "github.com/gdamore/tcell/v3"
import (
"log/slog"
"github.com/ayn2op/tview"
"github.com/gdamore/tcell/v3"
)
type LogoutEvent struct{ tcell.EventTime }
@ -17,3 +22,18 @@ func NewQuitEvent() *QuitEvent {
event.SetEventNow()
return event
}
func (v *View) closeState() tcell.Event {
if err := v.CloseState(); err != nil {
slog.Error("failed to close the session", "err", err)
return tcell.NewEventError(err)
}
return nil
}
func (v *View) logout() tview.Command {
return tview.BatchCommand{
tview.EventCommand(v.closeState),
tview.EventCommand(func() tcell.Event { return NewLogoutEvent() }),
}
}

View file

@ -260,10 +260,7 @@ func (v *View) HandleEvent(event tcell.Event) tview.Command {
v.focusNext()
return redraw
case keybind.Matches(event, v.cfg.Keybinds.Logout.Keybind):
if err := v.CloseState(); err != nil {
slog.Error("failed to close the session", "err", err)
}
return tview.EventCommand(func() tcell.Event { return NewLogoutEvent() })
return v.logout()
case keybind.Matches(event, v.cfg.Keybinds.ToggleGuildsTree.Keybind):
v.toggleGuildsTree()
return redraw