-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
77 lines (67 loc) · 2.33 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// ContentView.swift
// SalesSparrow
//
// Created by Mohit Charkha on 31/07/23.
//
import SwiftUI
import CoreData
/// The main view of the app,
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject var userStateViewModel: UserStateViewModel
@StateObject var loginScreenViewModel = LoginScreenViewModel()
@StateObject var toastViewModel = ToastViewModel.shared
@StateObject var alertViewModel = AlertViewModel.shared
@StateObject var loaderViewModel = LoaderViewModel.shared
@StateObject var safariWebViewModel = SafariWebViewModel.shared
/// The body of the view
var body: some View {
VStack {
if userStateViewModel.isAppLaunchInProgress {
LaunchScreen()
} else {
if !userStateViewModel.isUserLoggedIn {
LoginScreen()
} else {
HomeScreen()
}
}
}
.onOpenURL { incomingURL in
handleIncomingURL(incomingURL)
}
.environmentObject(loginScreenViewModel)
.toastView(toast: $toastViewModel.toast)
.overlay(content: {
if loaderViewModel.isLoaderVisible {
AppLoader()
}
if alertViewModel.isAlertVisible {
AlertModal()
}
})
.fullScreenCover(isPresented: $safariWebViewModel.isWebViewVisible) {
SafariWebView(url: URL(string: safariWebViewModel.url)!)
.ignoresSafeArea()
}
}
/// Handle incoming URLs from deep links with the custom URL scheme registered in the app's Info.plist
private func handleIncomingURL(_ url: URL) {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
print("Invalid URL")
return
}
let authToken = components.queryItems?.first(where: { $0.name == "code" })?.value
if (authToken) != nil {
safariWebViewModel.hideWebView()
loginScreenViewModel.salesforceConnect(authCode: authToken, onSuccess: {
}, onFailure: {})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}