Skip to content

Commit

Permalink
Delegate model update on event callback
Browse files Browse the repository at this point in the history
Keep a TODO to maybe remove it by using the list selection item index.
  • Loading branch information
didrocks committed Aug 9, 2023
1 parent bb349eb commit c7a6d45
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pam/authmodeselection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ type authModeSelected struct {
}

// selectAuthMode selects current authentication mode.
func (m *authModeSelectionModel) selectAuthMode(id string) tea.Cmd {
m.currentAuthModeSelectedID = id
func selectAuthMode(id string) tea.Cmd {
return func() tea.Msg {
return authModeSelected{
id: id,
Expand Down Expand Up @@ -87,6 +86,8 @@ func (m authModeSelectionModel) Update(msg tea.Msg) (authModeSelectionModel, tea
log.Infof(context.TODO(), "authentication mode %q is not part of currently available authentication mode", msg.id)
return m, nil
}
m.currentAuthModeSelectedID = msg.id // TODO: remove by getting current item on the list?

// Select correct line to ensure model is synchronised
for i, a := range m.Items() {
if a.(authModeItem).id != msg.id {
Expand Down Expand Up @@ -114,7 +115,7 @@ func (m authModeSelectionModel) Update(msg tea.Msg) (authModeSelectionModel, tea
return m, nil
}
authMode := item.(authModeItem)
cmd := m.selectAuthMode(authMode.id)
cmd := selectAuthMode(authMode.id)
return m, cmd
case "1", "2", "3", "4", "5", "6", "7", "8", "9":
// This is necessarily an integer, so above
Expand All @@ -125,7 +126,7 @@ func (m authModeSelectionModel) Update(msg tea.Msg) (authModeSelectionModel, tea
}
item := items[choice-1]
authMode := item.(authModeItem)
cmd := m.selectAuthMode(authMode.id)
cmd := selectAuthMode(authMode.id)
return m, cmd
}
}
Expand Down

0 comments on commit c7a6d45

Please sign in to comment.