Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions macOSdbApp/Models/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ final class AppState {

// MARK: - Actions

func refresh() async {
/// Loads the current product's releases, reusing any cached data. Used on launch
/// and when switching products so a flip doesn't re-download the whole catalog —
/// the DataProvider caches are product-keyed and URLCache serves repeat launches.
func load() async {
isLoading = true
lastError = nil
loadFailureMessage = nil
await dataProvider.clearCache()

do {
let fetched = try await dataProvider.fetchAllReleases(for: selectedProduct)
Expand All @@ -295,6 +297,13 @@ final class AppState {
isLoading = false
}

/// Discards cached data and reloads from the network. Backs the ⌘R Refresh
/// command so the user can pull in newly published releases.
func refresh() async {
await dataProvider.clearCache()
await load()
}

/// Re-point the current selection/comparison at the freshly loaded instances so
/// the detail panes don't keep rendering a stale snapshot (or a release that is
/// no longer in the catalog) after a refresh.
Expand All @@ -319,7 +328,7 @@ final class AppState {
}
isComparing = false
releases = []
Task { await refresh() }
Task { await load() }
}

func startCompare() {
Expand Down
2 changes: 1 addition & 1 deletion macOSdbApp/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct ContentView: View {
}
.task {
if appState.releases.isEmpty {
await appState.refresh()
await appState.load()
}
}
}
Expand Down