set authenticator and dataservice on the environmentobject

This commit is contained in:
Satindar Dhillon
2022-02-23 17:08:16 -08:00
parent b1655c06e4
commit 7f9f04989c
6 changed files with 15 additions and 21 deletions

View File

@ -1,6 +1,7 @@
import SwiftUI
import Views
// TODO: maybe this can be removed??
enum PrimaryContentCategory: Identifiable, Hashable, Equatable {
case feed(viewModel: HomeFeedViewModel)
case profile(viewModel: ProfileContainerViewModel)
@ -31,15 +32,6 @@ enum PrimaryContentCategory: Identifiable, Hashable, Equatable {
}
}
var selectedImage: Image {
switch self {
case .feed:
return .homeTabSelected
case .profile:
return .profileTabSelected
}
}
var listLabel: some View {
Label { Text(title) } icon: { image.renderingMode(.template) }
}

View File

@ -185,6 +185,8 @@ public struct RootView: View {
.frame(minWidth: 400, idealWidth: 1200, minHeight: 400, idealHeight: 1200)
#endif
}
.environmentObject(viewModel.services.authenticator)
.environmentObject(viewModel.services.dataService)
#if os(iOS)
.onOpenURL { url in
withoutAnimation {

View File

@ -11,9 +11,4 @@ public final class Services {
self.authenticator = Authenticator(networker: networker)
self.dataService = DataService(appEnvironment: appEnvironment, networker: networker)
}
public func switchAppEnvironment(to appEnvironment: AppEnvironment) {
authenticator.logout()
dataService.switchAppEnvironment(appEnvironment: appEnvironment)
}
}

View File

@ -1,16 +1,17 @@
import Models
import Services
import SwiftUI
import Views
struct DebugMenuView: View {
@EnvironmentObject var authenticator: Authenticator
@EnvironmentObject var dataService: DataService
@State private var selectedEnvironment: AppEnvironment
let appEnvironments: [AppEnvironment] = [.local, .demo, .dev, .prod]
let services: Services
init(services: Services) {
self._selectedEnvironment = State(initialValue: services.dataService.appEnvironment)
self.services = services
init(initialEnvironment: AppEnvironment) {
self._selectedEnvironment = State(initialValue: initialEnvironment)
}
var body: some View {
@ -28,7 +29,10 @@ struct DebugMenuView: View {
}
Button(
action: { services.switchAppEnvironment(to: selectedEnvironment) },
action: {
authenticator.logout()
dataService.switchAppEnvironment(appEnvironment: selectedEnvironment)
},
label: { Text("Apply Changes") }
)
.buttonStyle(SolidCapsuleButtonStyle(width: 220))

View File

@ -5,6 +5,7 @@ import Utils
import Views
struct WelcomeView: View {
@EnvironmentObject var dataService: DataService
@Environment(\.horizontalSizeClass) var horizontalSizeClass
let services: Services
@State private var showRegistrationView = false
@ -76,7 +77,7 @@ struct WelcomeView: View {
public var body: some View {
primaryContent()
.sheet(isPresented: $showDebugModal) {
DebugMenuView(services: services)
DebugMenuView(initialEnvironment: dataService.appEnvironment)
}
.onReceive(Publishers.keyboardHeight) { isKeyboardOnScreen = $0 > 1 }
}

View File

@ -1,7 +1,7 @@
import Foundation
import Models
public final class DataService {
public final class DataService: ObservableObject {
public static var registerIntercomUser: ((String) -> Void)?
public static var showIntercomMessenger: (() -> Void)?