diff --git a/Twigs/Budget/BudgetDetailsView.swift b/Twigs/Budget/BudgetDetailsView.swift index 443d2ef..c3b3fc1 100644 --- a/Twigs/Budget/BudgetDetailsView.swift +++ b/Twigs/Budget/BudgetDetailsView.swift @@ -17,7 +17,7 @@ struct BudgetDetailsView: View { var body: some View { InlineLoadingView( data: self.$dataStore.overview, - action: { await self.dataStore.loadOverview(self.budget) }, + action: { await self.dataStore.loadOverview(showLoader: false) }, errorTextLocalizedStringKey: "budgets_load_failure" ) { overview in List { @@ -33,7 +33,7 @@ struct BudgetDetailsView: View { } .listStyle(.insetGrouped) .refreshable { - await dataStore.loadOverview(self.budget) + await dataStore.loadOverview(showLoader: false) } .navigationBarItems(trailing: Button(action: { dataStore.editBudget() diff --git a/Twigs/DataStore.swift b/Twigs/DataStore.swift index f4e8900..c9075e2 100644 --- a/Twigs/DataStore.swift +++ b/Twigs/DataStore.swift @@ -154,8 +154,13 @@ class DataStore : ObservableObject { await self.selectBudget(budget) } - func loadOverview(_ budget: Budget) async { - self.overview = .loading + func loadOverview(showLoader: Bool = true) async { + guard case let .success(budget) = self.budget else { + return + } + if showLoader { + self.overview = .loading + } do { let budgetBalance = try await self.apiService.sumTransactions(budgetId: budget.id, categoryId: nil, from: nil, to: nil) let categories = try await self.apiService.getCategories(budgetId: budget.id, expense: nil, archived: false, count: nil, page: nil) @@ -190,7 +195,7 @@ class DataStore : ObservableObject { func selectBudget(_ budget: Budget?) async { if let budget = budget { self.budget = .success(budget) - await loadOverview(budget) + await loadOverview() await getTransactions() await getCategories(budgetId: budget.id, expense: nil, archived: nil, count: nil, page: nil) await getRecurringTransactions() @@ -221,15 +226,17 @@ class DataStore : ObservableObject { } @Published var selectedCategory: TwigsCore.Category? = nil - func getCategories() async { + func getCategories(showLoader: Bool = true) async { guard case let .success(budget) = self.budget else { return } - await self.getCategories(budgetId: budget.id) + await self.getCategories(budgetId: budget.id, showLoader: showLoader) } - func getCategories(budgetId: String, expense: Bool? = nil, archived: Bool? = false, count: Int? = nil, page: Int? = nil) async { - self.categories = .loading + func getCategories(budgetId: String, expense: Bool? = nil, archived: Bool? = false, count: Int? = nil, page: Int? = nil, showLoader: Bool = true) async { + if showLoader { + self.categories = .loading + } do { let categories = try await apiService.getCategories(budgetId: budgetId, expense: expense, archived: archived, count: count, page: page) self.categories = .success(categories) @@ -307,11 +314,13 @@ class DataStore : ObservableObject { } @Published var selectedRecurringTransaction: RecurringTransaction? = nil - func getRecurringTransactions() async { + func getRecurringTransactions(showLoader: Bool = true) async { guard case let .success(budget) = self.budget else { return } - self.recurringTransactions = .loading + if showLoader { + self.recurringTransactions = .loading + } do { let transactions = try await self.apiService.getRecurringTransactions(budget.id) self.recurringTransactions = .success(transactions.sorted(by: { $0.title < $1.title })) @@ -398,12 +407,14 @@ class DataStore : ObservableObject { } @Published var selectedTransaction: Transaction? = nil - func getTransactions() async { + func getTransactions(showLoader: Bool = true) async { guard let budgetId = self.budgetId else { self.transactions = .error(NetworkError.unknown) return } - self.transactions = .loading + if showLoader { + self.transactions = .loading + } do { var categoryIds: [String] = [] if let categoryId = categoryId { diff --git a/Twigs/Recurring Transactions/RecurringTransactionsListView.swift b/Twigs/Recurring Transactions/RecurringTransactionsListView.swift index c9e27d5..ddf9f5f 100644 --- a/Twigs/Recurring Transactions/RecurringTransactionsListView.swift +++ b/Twigs/Recurring Transactions/RecurringTransactionsListView.swift @@ -23,6 +23,9 @@ struct RecurringTransactionsListView: View { RecurringTransactionsListItemView(transaction) } } + .refreshable { + await dataStore.getRecurringTransactions(showLoader: false) + } } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { diff --git a/Twigs/Transaction/TransactionListView.swift b/Twigs/Transaction/TransactionListView.swift index 252566a..ecb5fe3 100644 --- a/Twigs/Transaction/TransactionListView.swift +++ b/Twigs/Transaction/TransactionListView.swift @@ -95,7 +95,7 @@ struct TransactionListView: View where Content: View { } .searchable(text: $search) .refreshable { - await dataStore.getTransactions() + await dataStore.getTransactions(showLoader: false) } .sheet( isPresented: .constant(addingTransaction),