Skip to content

Commit

Permalink
[CAP-5312] Fix stuck on loading screen (#158)
Browse files Browse the repository at this point in the history
* Move login io to cmd

* Make loading screen consistent

* Simplify messages
  • Loading branch information
mdbenjam authored Dec 4, 2024
1 parent e3226e1 commit ba104d3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/tui/views/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/renderinc/cli/pkg/tui"
)

type notLoggedInMsg struct{}

func NonInteractiveLogin(cmd *cobra.Command) error {
dc := oauth.NewClient(cfg.GetHost())
vc := version.NewClient(cfg.RepoURL)
Expand Down Expand Up @@ -145,16 +147,24 @@ func pollForLogin(ctx context.Context, dc *oauth.Client, msg loginStartedMsg) te
}

func (l *LoginView) Init() tea.Cmd {
alreadyLoggedIn := isAlreadyLoggedIn(l.ctx)
if alreadyLoggedIn {
return nil
}

return startLogin(l.ctx, l.dc)
return tea.Sequence(
func() tea.Msg { return tui.LoadingDataMsg{} },
func() tea.Msg {
if isAlreadyLoggedIn(l.ctx) {
return tui.DoneMsg{}
} else {
return notLoggedInMsg{}
}
},
)
}

func (l *LoginView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case notLoggedInMsg:
return l, tea.Sequence(func() tea.Msg {
return tui.DoneLoadingDataMsg{}
}, startLogin(l.ctx, l.dc))
case loginStartedMsg:
l.dashURL = msg.dashURL
return l, tea.Batch(func() tea.Msg {
Expand Down

0 comments on commit ba104d3

Please sign in to comment.