Skip to content

Commit

Permalink
Wrap view tasks into tasks
Browse files Browse the repository at this point in the history
Yo dawg, I heard you like tasks. So I put a task around your task, so the task is a separate task that won't get cancelled when task gets cancelled.

I hope this fixes issue #167 without too much changes in the API.

The other solution would maybe be to add task ids:
@State private var taskId: UUID = .init()
.task(id: taskId) {
  • Loading branch information
supergeorg committed Jun 3, 2023
1 parent 6ca3b80 commit 5b2c45b
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 27 deletions.
4 changes: 3 additions & 1 deletion Shared/Views/Admin/UserManagementView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ struct UserManagementView: View {
}
.navigationTitle(LocalizedStringKey("str.admin.user"))
.task {
await updateData()
Task {
await updateData()
}
}
.refreshable {
await updateData()
Expand Down
8 changes: 6 additions & 2 deletions Shared/Views/MasterData/MDBarcodesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ struct MDBarcodesView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.toast(
item: $toastType,
Expand Down Expand Up @@ -176,7 +178,9 @@ struct MDBarcodesView: View {
}
.navigationTitle(LocalizedStringKey("str.md.barcodes"))
.task {
await updateData()
Task {
await updateData()
}
}
.refreshable {
await updateData()
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDLocationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ struct MDLocationsView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDProductGroupsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ struct MDProductGroupsView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDProductsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ struct MDProductsView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDQuantityUnitsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ struct MDQuantityUnitsView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDShoppingLocationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ struct MDStoresView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDTaskCategoriesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ struct MDTaskCategoriesView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDUserEntitiesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ struct MDUserEntitiesView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/MasterData/MDUserFieldsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ struct MDUserFieldsView: View {
}
}
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.refreshable {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/Recipes/RecipesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ struct RecipesView: View {
await updateData()
})
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString, prompt: LocalizedStringKey("str.search"))
.animation(.default, value: recipes.count)
Expand Down
6 changes: 4 additions & 2 deletions Shared/Views/Settings/SettingsShoppingListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ struct SettingsShoppingListView: View {
.navigationTitle(LocalizedStringKey("str.settings.shoppingList"))
.task {
if isFirst {
await grocyVM.requestData(objects: dataToUpdate)
isFirst = false
Task {
await grocyVM.requestData(objects: dataToUpdate)
isFirst = false
}
}
}
.onDisappear(perform: {
Expand Down
6 changes: 4 additions & 2 deletions Shared/Views/Settings/SettingsStockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ struct SettingsStockView: View {
.navigationTitle(LocalizedStringKey("str.settings.stock"))
.task {
if isFirst {
await grocyVM.requestData(objects: dataToUpdate)
isFirst = false
Task {
await grocyVM.requestData(objects: dataToUpdate)
isFirst = false
}
}
}
.onDisappear(perform: {
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ struct SettingsView: View {
}
}
.task {
await grocyVM.requestData(additionalObjects: [.system_info, .current_user])
Task {
await grocyVM.requestData(additionalObjects: [.system_info, .current_user])
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/ShoppingList/ShoppingListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ struct ShoppingListView: View {
}
.navigationTitle(LocalizedStringKey("str.shL"))
.task {
await updateData()
Task {
await updateData()
}
}
.searchable(text: $searchString,
prompt: LocalizedStringKey("str.search"))
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/Stock/StockEntriesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ struct StockEntriesView: View {
}
.animation(.default, value: stockEntries.count)
.task {
await fetchData(ignoreCachedStock: false)
Task {
await fetchData(ignoreCachedStock: false)
}
}
.toast(
item: $toastType,
Expand Down
6 changes: 4 additions & 2 deletions Shared/Views/Stock/StockJournalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,10 @@ struct StockJournalView: View {
value: filteredJournal.count
)
.task {
await updateData()
filteredProductID = selectedProductID
Task {
await updateData()
filteredProductID = selectedProductID
}
}
.toast(isPresented: $showToastUndoFailed, isSuccess: false, text: LocalizedStringKey("str.stock.journal.undo.failed"))
}
Expand Down
12 changes: 8 additions & 4 deletions Shared/Views/Stock/StockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ struct StockView: View {
.animation(.default, value: sortSetting)
.task {
if firstAppear {
await updateData()
firstAppear = false
Task {
await updateData()
firstAppear = false
}
}
}
.toast(
Expand Down Expand Up @@ -450,8 +452,10 @@ struct StockView: View {
.animation(.default, value: groupedProducts.count)
.task {
if firstAppear {
await updateData()
firstAppear = false
Task {
await updateData()
firstAppear = false
}
}
}
.toast(
Expand Down
4 changes: 3 additions & 1 deletion iOS/ActivitiesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct ActivitiesView: View {
}
.navigationTitle(LocalizedStringKey("str.nav.activities"))
.task {
await grocyVM.requestData(objects: [.userentities])
Task {
await grocyVM.requestData(objects: [.userentities])
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion iOS/QuickScan/QuickScanModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ struct QuickScanModeView: View {
}
})
.task {
await updateData()
Task {
await updateData()
}
}
.onChange(of: newRecognizedBarcode?.id, perform: { _ in
DispatchQueue.main.async {
Expand Down

0 comments on commit 5b2c45b

Please sign in to comment.