Update implements tea.Model.
(msg tea.Msg)
| 141 | |
| 142 | // Update implements tea.Model. |
| 143 | func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 144 | switch msg := msg.(type) { |
| 145 | case tea.WindowSizeMsg: |
| 146 | a.width = msg.Width |
| 147 | a.height = msg.Height |
| 148 | a.pricingView.Width = msg.Width |
| 149 | a.pricingView.Height = msg.Height |
| 150 | a.historyView.Width = msg.Width |
| 151 | a.historyView.Height = msg.Height |
| 152 | a.settingsView.Width = msg.Width |
| 153 | a.settingsView.Height = msg.Height |
| 154 | |
| 155 | case tickMsg: |
| 156 | a.loadingFrame = (a.loadingFrame + 1) % 8 |
| 157 | if a.refreshMsgFrames > 0 { |
| 158 | a.refreshMsgFrames-- |
| 159 | if a.refreshMsgFrames == 0 { |
| 160 | a.metadataRefreshMsg = "" |
| 161 | } |
| 162 | } |
| 163 | return a, tickCmd() |
| 164 | |
| 165 | case tea.KeyMsg: |
| 166 | return a.handleKey(msg) |
| 167 | |
| 168 | case authResultMsg: |
| 169 | if msg.err != nil { |
| 170 | a.errorMsg = msg.err.Error() |
| 171 | a.authState = AuthStateError |
| 172 | return a, nil |
| 173 | } |
| 174 | cfg := &config.Config{CliID: msg.cliID, APIKey: &msg.apiKey} |
| 175 | if err := a.client.SaveConfig(cfg); err != nil { |
| 176 | a.errorMsg = err.Error() |
| 177 | a.authState = AuthStateError |
| 178 | return a, nil |
| 179 | } |
| 180 | a.authState = AuthStateLoading |
| 181 | a.loadingFrame = 0 |
| 182 | return a, downloadMetadataCmd(a.client) |
| 183 | |
| 184 | case metadataReadyMsg: |
| 185 | if msg.err != nil { |
| 186 | if a.viewMode == ViewModeInitAuth { |
| 187 | a.errorMsg = msg.err.Error() |
| 188 | a.authState = AuthStateError |
| 189 | } else { |
| 190 | a.metadataRefreshMsg = "Refresh Error: " + msg.err.Error() |
| 191 | a.refreshMsgFrames = 120 |
| 192 | a.authState = AuthStatePrompt |
| 193 | } |
| 194 | return a, nil |
| 195 | } |
| 196 | a.loadMetadataIntoView() |
| 197 | if a.viewMode == ViewModeInitAuth { |
| 198 | a.viewMode = ViewModePricing |
| 199 | a.authState = AuthStatePrompt |
| 200 | } else { |
nothing calls this directly
no test coverage detected