on main help sign in
refactor: remove init in favor of returning cmd on new
9f7be9dAndrey Nering
internal/ui/dialog/oauth.go+2−7
@@ -71,7 +71,7 @@ type OAuth struct {
71var _ Dialog = (*OAuth)(nil)
71var _ Dialog = (*OAuth)(nil)
72
72
73// newOAuth creates a new device flow component.
73// newOAuth creates a new device flow component.
74−func newOAuth(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType, oAuthProvider OAuthProvider) (*OAuth, error) {
74+func newOAuth(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType, oAuthProvider OAuthProvider) (*OAuth, tea.Cmd) {
75 t := com.Styles
75 t := com.Styles
76
76
77 m := OAuth{}
77 m := OAuth{}
@@ -101,7 +101,7 @@ func newOAuth(com *common.Common, provider catwalk.Provider, model config.Select
101 )
101 )
102 m.keyMap.Close = CloseKey
102 m.keyMap.Close = CloseKey
103
103
104− return &m, nil
104+ return &m, tea.Batch(m.spinner.Tick, m.oAuthProvider.initiateAuth)
105}
105}
106
106
107// ID implements Dialog.
107// ID implements Dialog.
@@ -109,11 +109,6 @@ func (m *OAuth) ID() string {
109 return OAuthID
109 return OAuthID
110}
110}
111
111
112−// Init implements Dialog.
113−func (m *OAuth) Init() tea.Cmd {
114− return tea.Batch(m.spinner.Tick, m.oAuthProvider.initiateAuth)
115−}
116−
117// HandleMsg handles messages and state transitions.
112// HandleMsg handles messages and state transitions.
118func (m *OAuth) HandleMsg(msg tea.Msg) Action {
113func (m *OAuth) HandleMsg(msg tea.Msg) Action {
119 switch msg := msg.(type) {
114 switch msg := msg.(type) {
internal/ui/dialog/oauth_copilot.go+1−1
@@ -12,7 +12,7 @@ import (
12 "github.com/charmbracelet/crush/internal/ui/common"
12 "github.com/charmbracelet/crush/internal/ui/common"
13)
13)
14
14
15−func NewOAuthCopilot(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*OAuth, error) {
15+func NewOAuthCopilot(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*OAuth, tea.Cmd) {
16 return newOAuth(com, provider, model, modelType, &OAuthCopilot{})
16 return newOAuth(com, provider, model, modelType, &OAuthCopilot{})
17}
17}
18
18
internal/ui/dialog/oauth_hyper.go+1−1
@@ -12,7 +12,7 @@ import (
12 "github.com/charmbracelet/crush/internal/ui/common"
12 "github.com/charmbracelet/crush/internal/ui/common"
13)
13)
14
14
15−func NewOAuthHyper(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*OAuth, error) {
15+func NewOAuthHyper(com *common.Common, provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) (*OAuth, tea.Cmd) {
16 return newOAuth(com, provider, model, modelType, &OAuthHyper{})
16 return newOAuth(com, provider, model, modelType, &OAuthHyper{})
17}
17}
18
18
internal/ui/model/ui.go+4−12
@@ -1058,13 +1058,9 @@ func (m *UI) openOAuthHyperDialog(provider catwalk.Provider, model config.Select
1058 return nil
1058 return nil
1059 }
1059 }
1060
1060
1061− oAuthDialog, err := dialog.NewOAuthHyper(m.com, provider, model, modelType)
1061+ oAuthDialog, cmd := dialog.NewOAuthHyper(m.com, provider, model, modelType)
1062− if err != nil {
1063− return uiutil.ReportError(err)
1064− }
1065 m.dialog.OpenDialog(oAuthDialog)
1062 m.dialog.OpenDialog(oAuthDialog)
1066−
1067− return oAuthDialog.Init()
1063+ return cmd
1068}
1064}
1069
1065
1070func (m *UI) openOAuthCopilotDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
1066func (m *UI) openOAuthCopilotDialog(provider catwalk.Provider, model config.SelectedModel, modelType config.SelectedModelType) tea.Cmd {
@@ -1073,13 +1069,9 @@ func (m *UI) openOAuthCopilotDialog(provider catwalk.Provider, model config.Sele
1073 return nil
1069 return nil
1074 }
1070 }
1075
1071
1076− oAuthDialog, err := dialog.NewOAuthCopilot(m.com, provider, model, modelType)
1072+ oAuthDialog, cmd := dialog.NewOAuthCopilot(m.com, provider, model, modelType)
1077− if err != nil {
1078− return uiutil.ReportError(err)
1079− }
1080 m.dialog.OpenDialog(oAuthDialog)
1073 m.dialog.OpenDialog(oAuthDialog)
1081−
1082− return oAuthDialog.Init()
1074+ return cmd
1083}
1075}
1084
1076
1085func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
1077func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {