(event views.HistoryEvent, idx int)
| 317 | } |
| 318 | |
| 319 | func (a App) handleHistoryEvent(event views.HistoryEvent, idx int) (tea.Model, tea.Cmd) { |
| 320 | switch event { |
| 321 | case views.HistoryEventQuit: |
| 322 | return a, tea.Quit |
| 323 | case views.HistoryEventNextView: |
| 324 | a.switchViewNext() |
| 325 | case views.HistoryEventPrevView: |
| 326 | a.switchViewPrev() |
| 327 | case views.HistoryEventClearAll: |
| 328 | if a.db != nil { |
| 329 | a.db.ClearAll() |
| 330 | a.historyView.History, _ = a.db.GetHistory(100) |
| 331 | a.historyView.SelectedResults = nil |
| 332 | } |
| 333 | case views.HistoryEventOpenInPricing: |
| 334 | if idx < len(a.historyView.History) { |
| 335 | h := a.historyView.History[idx] |
| 336 | a.pricingView.CommandBuilder.ProductTags = splitNonEmpty(h.ProductFamilies, ",") |
| 337 | a.pricingView.CommandBuilder.RegionTags = splitNonEmpty(h.Regions, ",") |
| 338 | a.pricingView.CommandBuilder.AttributeTags = splitNonEmpty(h.Attributes, ",") |
| 339 | a.pricingView.CommandBuilder.PriceTags = splitNonEmpty(h.Prices, ",") |
| 340 | a.viewMode = ViewModePricing |
| 341 | a.pricingView.ActiveSection = views.PricingSectionCommand |
| 342 | |
| 343 | // Try cache first |
| 344 | if a.db != nil { |
| 345 | if cached, _ := a.db.GetCache(h.CacheKey); cached != nil { |
| 346 | a.pricingView.Items = views.ConvertResponse(cached) |
| 347 | a.pricingView.FilteredItems = append([]views.PricingDisplayItem{}, a.pricingView.Items...) |
| 348 | a.pricingView.Selected = 0 |
| 349 | a.pricingView.Loading = false |
| 350 | if len(a.pricingView.FilteredItems) > 0 { |
| 351 | a.pricingView.ActiveSection = views.PricingSectionResults |
| 352 | } |
| 353 | return a, nil |
| 354 | } |
| 355 | } |
| 356 | return a.submitPricingQuery() |
| 357 | } |
| 358 | case views.HistoryEventNone: |
| 359 | // Update preview for selected history item |
| 360 | if a.db != nil && idx < len(a.historyView.History) { |
| 361 | h := a.historyView.History[a.historyView.Selected] |
| 362 | if cached, _ := a.db.GetCache(h.CacheKey); cached != nil { |
| 363 | a.historyView.SelectedResults = views.ConvertResponse(cached) |
| 364 | } else { |
| 365 | a.historyView.SelectedResults = nil |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | return a, nil |
| 370 | } |
| 371 | |
| 372 | func (a App) handleSettingsEvent(event views.SettingsEvent) (tea.Model, tea.Cmd) { |
| 373 | switch event { |
no test coverage detected