Fix some async loading issues

This commit is contained in:
William Brawner 2022-01-06 18:24:50 -06:00
parent ec425642b4
commit 4b5a6c6558
5 changed files with 18 additions and 13 deletions

View file

@ -75,12 +75,6 @@ struct SidebarBudgetView: View {
} }
} }
}) })
.sheet(isPresented: $budgetDataStore.showBudgetSelection,
content: {
List {
BudgetListsView().environmentObject(budgetDataStore)
}
})
.interactiveDismissDisabled(true) .interactiveDismissDisabled(true)
} }
} }

View file

@ -12,7 +12,7 @@ import TwigsCore
struct TabbedBudgetView: View { struct TabbedBudgetView: View {
@EnvironmentObject var authenticationDataStore: AuthenticationDataStore @EnvironmentObject var authenticationDataStore: AuthenticationDataStore
@EnvironmentObject var budgetDataStore: BudgetsDataStore @EnvironmentObject var budgetDataStore: BudgetsDataStore
@EnvironmentObject var apiService: TwigsInMemoryCacheService @EnvironmentObject var apiService: TwigsApiService
@State var tabSelection: Int = 0 @State var tabSelection: Int = 0
@ViewBuilder @ViewBuilder

View file

@ -11,6 +11,7 @@ import Combine
import Collections import Collections
import TwigsCore import TwigsCore
@MainActor
class TransactionDataStore: ObservableObject { class TransactionDataStore: ObservableObject {
@Published var transactions: AsyncData<OrderedDictionary<String, [Transaction]>> = .empty @Published var transactions: AsyncData<OrderedDictionary<String, [Transaction]>> = .empty
@Published var transaction: AsyncData<Transaction> = .empty { @Published var transaction: AsyncData<Transaction> = .empty {

View file

@ -56,7 +56,7 @@ struct TransactionFormSheet: View {
} else { } else {
EmptyView() EmptyView()
} }
} }.environmentObject(transactionForm)
} }
} }
} }

View file

@ -11,11 +11,21 @@ import TwigsCore
struct MainView: View { struct MainView: View {
@StateObject var authenticationDataStore: AuthenticationDataStore @StateObject var authenticationDataStore: AuthenticationDataStore
@StateObject var budgetDataStore: BudgetsDataStore
@StateObject var transactionList: TransactionDataStore
@StateObject var categoryList: CategoryListDataStore
@StateObject var userDataStore: UserDataStore
@StateObject var recurringTransactionList: RecurringTransactionDataStore
let apiService: TwigsApiService let apiService: TwigsApiService
init(_ apiService: TwigsApiService, baseUrl: Binding<String>, token: Binding<String>, userId: Binding<String>) { init(_ apiService: TwigsApiService, baseUrl: Binding<String>, token: Binding<String>, userId: Binding<String>) {
self.apiService = apiService self.apiService = apiService
self._authenticationDataStore = StateObject(wrappedValue: AuthenticationDataStore(apiService, baseUrl: baseUrl, token: token, userId: userId)) self._authenticationDataStore = StateObject(wrappedValue: AuthenticationDataStore(apiService, baseUrl: baseUrl, token: token, userId: userId))
self._budgetDataStore = StateObject(wrappedValue: BudgetsDataStore(budgetRepository: apiService, categoryRepository: apiService, transactionRepository: apiService))
self._categoryList = StateObject(wrappedValue: CategoryListDataStore(apiService))
self._userDataStore = StateObject(wrappedValue: UserDataStore(apiService))
self._transactionList = StateObject(wrappedValue: TransactionDataStore(apiService))
self._recurringTransactionList = StateObject(wrappedValue: RecurringTransactionDataStore(apiService))
} }
@ViewBuilder @ViewBuilder
@ -29,11 +39,11 @@ struct MainView: View {
var body: some View { var body: some View {
mainView mainView
.environmentObject(TransactionDataStore(apiService)) .environmentObject(transactionList)
.environmentObject(CategoryListDataStore(apiService)) .environmentObject(categoryList)
.environmentObject(BudgetsDataStore(budgetRepository: apiService, categoryRepository: apiService, transactionRepository: apiService)) .environmentObject(budgetDataStore)
.environmentObject(UserDataStore(apiService)) .environmentObject(userDataStore)
.environmentObject(RecurringTransactionDataStore(apiService)) .environmentObject(recurringTransactionList)
.environmentObject(authenticationDataStore) .environmentObject(authenticationDataStore)
.onAppear { .onAppear {
Task { Task {