diff --git a/internal/ui/chat/events.go b/internal/ui/chat/events.go index 95440ef..190d7f4 100644 --- a/internal/ui/chat/events.go +++ b/internal/ui/chat/events.go @@ -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() }), + } +} diff --git a/internal/ui/chat/view.go b/internal/ui/chat/view.go index 1cdf168..e5dc258 100644 --- a/internal/ui/chat/view.go +++ b/internal/ui/chat/view.go @@ -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