twigs-ios/Twigs/Views/MainView.swift

46 lines
1.1 KiB
Swift
Raw Normal View History

2022-01-03 17:56:43 +00:00
//
// MainView.swift
// Twigs
//
// Created by William Brawner on 12/30/21.
// Copyright © 2021 William Brawner. All rights reserved.
//
import SwiftUI
import TwigsCore
struct MainView: View {
@StateObject var dataStore: DataStore
2022-01-03 17:56:43 +00:00
let apiService: TwigsApiService
init(_ apiService: TwigsApiService) {
2022-01-03 17:56:43 +00:00
self.apiService = apiService
2023-07-26 22:17:04 +00:00
self._dataStore = StateObject(wrappedValue: DataStore(apiService, errorReporter: LoggingErrorReporter()))
2022-01-03 17:56:43 +00:00
}
@ViewBuilder
var mainView: some View {
if UIDevice.current.userInterfaceIdiom == .mac || UIDevice.current.userInterfaceIdiom == .pad {
SidebarBudgetView()
2022-01-03 17:56:43 +00:00
} else {
TabbedBudgetView()
2022-01-03 17:56:43 +00:00
}
}
var body: some View {
mainView
.environmentObject(dataStore)
.onAppear {
Task {
await self.dataStore.loadProfile()
}
2022-01-03 17:56:43 +00:00
}
}
}
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView(TwigsInMemoryCacheService())
2022-01-03 17:56:43 +00:00
}
}