on main help sign in
refactor: remove duplication on functions to open dialogs
8b5cc43Andrey Nering
internal/ui/dialog/api_key_input.go+1−1
@@ -54,7 +54,7 @@ type APIKeyInput struct {
54var _ Dialog = (*APIKeyInput)(nil)
54var _ Dialog = (*APIKeyInput)(nil)
55
55
56// NewAPIKeyInput creates a new Models dialog.
56// NewAPIKeyInput creates a new Models dialog.
57−func NewAPIKeyInput(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*APIKeyInput, error) {
57+func NewAPIKeyInput(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*APIKeyInput, tea.Cmd) {
58 t := com.Styles
58 t := com.Styles
59
59
60 m := APIKeyInput{}
60 m := APIKeyInput{}
internal/ui/model/ui.go+11−34
@@ -1028,49 +1028,26 @@ func substituteArgs(content string, args map[string]string) string {
1028}
1028}
1029
1029
1030func (m *UI) openAuthenticationDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1030func (m *UI) openAuthenticationDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1031+ var (
1032+ dlg dialog.Dialog
1033+ cmd tea.Cmd
1034+ )
1035+
1031 switch provider.ID {
1036 switch provider.ID {
1032 case "hyper":
1037 case "hyper":
1033− return m.openOAuthHyperDialog(provider, model, modelType)
1038+ dlg, cmd = dialog.NewOAuthHyper(m.com, provider, model, modelType)
1034 case catwalk.InferenceProviderCopilot:
1039 case catwalk.InferenceProviderCopilot:
1035− return m.openOAuthCopilotDialog(provider, model, modelType)
1040+ dlg, cmd = dialog.NewOAuthCopilot(m.com, provider, model, modelType)
1036 default:
1041 default:
1037− return m.openAPIKeyInputDialog(provider, model, modelType)
1038− }
1039−}
1040−
1041−func (m *UI) openAPIKeyInputDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1042− if m.dialog.ContainsDialog(dialog.APIKeyInputID) {
1043− m.dialog.BringToFront(dialog.APIKeyInputID)
1044− return nil
1045− }
1046−
1047− apiKeyInputDialog, err := dialog.NewAPIKeyInput(m.com, provider, model, modelType)
1042+ dlg, cmd = dialog.NewAPIKeyInput(m.com, provider, model, modelType)
1048− if err != nil {
1049− return uiutil.ReportError(err)
1050 }
1043 }
1051− m.dialog.OpenDialog(apiKeyInputDialog)
1052− return nil
1053−}
1054−
1055−func (m *UI) openOAuthHyperDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1056− if m.dialog.ContainsDialog(dialog.OAuthID) {
1057− m.dialog.BringToFront(dialog.OAuthID)
1058− return nil
1059− }
1060−
1061− oAuthDialog, cmd := dialog.NewOAuthHyper(m.com, provider, model, modelType)
1062− m.dialog.OpenDialog(oAuthDialog)
1063− return cmd
1064−}
1065
1044
1066−func (m *UI) openOAuthCopilotDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1067− if m.dialog.ContainsDialog(dialog.OAuthID) {
1045+ if m.dialog.ContainsDialog(dlg.ID()) {
1068− m.dialog.BringToFront(dialog.OAuthID)
1046+ m.dialog.BringToFront(dlg.ID())
1069 return nil
1047 return nil
1070 }
1048 }
1071
1049
1072− oAuthDialog, cmd := dialog.NewOAuthCopilot(m.com, provider, model, modelType)
1073− m.dialog.OpenDialog(oAuthDialog)
1050+ m.dialog.OpenDialog(dlg)
1074 return cmd
1051 return cmd
1075}
1052}
1076
1053