From 8b5cc439a99cdf71bc8c66b62d4ed4471260585b Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 15 Jan 2026 16:53:53 -0300 Subject: [PATCH] refactor: remove duplication on functions to open dialogs Co-authored-by: Ayman Bagabas --- internal/ui/dialog/api_key_input.go | 2 +- internal/ui/model/ui.go | 45 +++++++---------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/internal/ui/dialog/api_key_input.go b/internal/ui/dialog/api_key_input.go index e28dea2b823143d176d796c8775e8024df61d0bb..430f7b4629294faa83bad9b5b90ca363ceb6f1b7 100644 --- a/internal/ui/dialog/api_key_input.go +++ b/internal/ui/dialog/api_key_input.go @@ -54,7 +54,7 @@ type APIKeyInput struct { var _ Dialog = (*APIKeyInput)(nil) // NewAPIKeyInput creates a new Models dialog. -func NewAPIKeyInput(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*APIKeyInput, error) { +func NewAPIKeyInput(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*APIKeyInput, tea.Cmd) { t := com.Styles m := APIKeyInput{} diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 4d3ecafe07eeb3a88c4b88f90bc60b0fe4d8266e..de4b0e91fc38ec280ad9d9249ab17e88dedcf748 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -1028,49 +1028,26 @@ func substituteArgs(content string, args map[string]string) string { } func (m *UI) openAuthenticationDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd { + var ( + dlg dialog.Dialog + cmd tea.Cmd + ) + switch provider.ID { case "hyper": - return m.openOAuthHyperDialog(provider, model, modelType) + dlg, cmd = dialog.NewOAuthHyper(m.com, provider, model, modelType) case catwalk.InferenceProviderCopilot: - return m.openOAuthCopilotDialog(provider, model, modelType) + dlg, cmd = dialog.NewOAuthCopilot(m.com, provider, model, modelType) default: - return m.openAPIKeyInputDialog(provider, model, modelType) - } -} - -func (m *UI) openAPIKeyInputDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd { - if m.dialog.ContainsDialog(dialog.APIKeyInputID) { - m.dialog.BringToFront(dialog.APIKeyInputID) - return nil - } - - apiKeyInputDialog, err := dialog.NewAPIKeyInput(m.com, provider, model, modelType) - if err != nil { - return uiutil.ReportError(err) + dlg, cmd = dialog.NewAPIKeyInput(m.com, provider, model, modelType) } - m.dialog.OpenDialog(apiKeyInputDialog) - return nil -} - -func (m *UI) openOAuthHyperDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd { - if m.dialog.ContainsDialog(dialog.OAuthID) { - m.dialog.BringToFront(dialog.OAuthID) - return nil - } - - oAuthDialog, cmd := dialog.NewOAuthHyper(m.com, provider, model, modelType) - m.dialog.OpenDialog(oAuthDialog) - return cmd -} -func (m *UI) openOAuthCopilotDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd { - if m.dialog.ContainsDialog(dialog.OAuthID) { - m.dialog.BringToFront(dialog.OAuthID) + if m.dialog.ContainsDialog(dlg.ID()) { + m.dialog.BringToFront(dlg.ID()) return nil } - oAuthDialog, cmd := dialog.NewOAuthCopilot(m.com, provider, model, modelType) - m.dialog.OpenDialog(oAuthDialog) + m.dialog.OpenDialog(dlg) return cmd }