2020-07-29 23:50:30 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
struct RootView: View {
|
2020-07-29 23:50:30 +00:00
|
|
|
@EnvironmentObject var sceneViewModel: SceneViewModel
|
|
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
|
|
|
|
|
|
var body: some View {
|
2020-07-31 21:40:57 +00:00
|
|
|
if let identity = sceneViewModel.identity {
|
|
|
|
mainNavigation(identity: identity)
|
2020-07-29 23:50:30 +00:00
|
|
|
.onChange(of: scenePhase) {
|
|
|
|
if case .active = $0 {
|
|
|
|
sceneViewModel.refreshIdentity()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.alertItem($sceneViewModel.alertItem)
|
|
|
|
} else {
|
|
|
|
addIdentity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
private extension RootView {
|
2020-07-31 21:40:57 +00:00
|
|
|
private func mainNavigation(identity: Identity) -> some View {
|
2020-07-29 23:50:30 +00:00
|
|
|
#if os(macOS)
|
2020-08-02 22:23:01 +00:00
|
|
|
return SidebarNavigation(identity: identity)
|
|
|
|
.frame(minWidth: 900, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
|
2020-07-29 23:50:30 +00:00
|
|
|
#else
|
2020-07-31 21:40:57 +00:00
|
|
|
return TabNavigation(identity: identity)
|
2020-07-29 23:50:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private var addIdentity: some View {
|
|
|
|
AddIdentityView(viewModel: sceneViewModel.addIdentityViewModel())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 21:40:57 +00:00
|
|
|
#if DEBUG
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-08-03 15:20:51 +00:00
|
|
|
RootView()
|
2020-07-31 21:40:57 +00:00
|
|
|
.environmentObject(SceneViewModel.development)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|