set authenticator and dataservice on the environmentobject
This commit is contained in:
@ -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) }
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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 }
|
||||
}
|
||||
|
||||
@ -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)?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user