diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj index 82e2e3e..846313f 100644 --- a/base/base.xcodeproj/project.pbxproj +++ b/base/base.xcodeproj/project.pbxproj @@ -19,7 +19,7 @@ 2937EB7629636BEB00BBC0E6 /* RegisterNetworking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2329636BEA00BBC0E6 /* RegisterNetworking.swift */; }; 2937EB7729636BEB00BBC0E6 /* RegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2429636BEA00BBC0E6 /* RegisterViewModel.swift */; }; 2937EB7829636BEB00BBC0E6 /* RegisterFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */; }; - 2937EB7929636BEB00BBC0E6 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */; }; + 2937EB7929636BEB00BBC0E6 /* RegisterScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */; }; 2937EB8029636BEB00BBC0E6 /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2F29636BEA00BBC0E6 /* ImageView.swift */; }; 2937EB8129636BEB00BBC0E6 /* Taskable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB3129636BEA00BBC0E6 /* Taskable.swift */; }; 2937EB8229636BEB00BBC0E6 /* Usable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB3229636BEA00BBC0E6 /* Usable.swift */; }; @@ -92,7 +92,7 @@ 2937EB2329636BEA00BBC0E6 /* RegisterNetworking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterNetworking.swift; sourceTree = ""; }; 2937EB2429636BEA00BBC0E6 /* RegisterViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterViewModel.swift; sourceTree = ""; }; 2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterFields.swift; sourceTree = ""; }; - 2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginScreen.swift; sourceTree = ""; }; + 2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterScreen.swift; sourceTree = ""; }; 2937EB2F29636BEA00BBC0E6 /* ImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = ""; }; 2937EB3129636BEA00BBC0E6 /* Taskable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Taskable.swift; sourceTree = ""; }; 2937EB3229636BEA00BBC0E6 /* Usable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Usable.swift; sourceTree = ""; }; @@ -257,7 +257,7 @@ 2937EB2229636BEA00BBC0E6 /* Register */, 2937EB1F29636BEA00BBC0E6 /* ProfileScreen.swift */, 2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */, - 2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */, + 2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */, ); path = Profile; sourceTree = ""; @@ -657,7 +657,7 @@ 2937EB8229636BEB00BBC0E6 /* Usable.swift in Sources */, 2937EB8D29636BEB00BBC0E6 /* ForwardNavigatable.swift in Sources */, 2937EB9529636BEB00BBC0E6 /* CartographyAlert.swift in Sources */, - 2937EB7929636BEB00BBC0E6 /* LoginScreen.swift in Sources */, + 2937EB7929636BEB00BBC0E6 /* RegisterScreen.swift in Sources */, 2937EB7029636BEB00BBC0E6 /* HomeScreen.swift in Sources */, 2937EBA729636BEB00BBC0E6 /* User.swift in Sources */, 2937EB9229636BEB00BBC0E6 /* AlertPresenting.swift in Sources */, @@ -774,7 +774,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.1; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -828,7 +828,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.1; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -983,8 +983,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/0xOpenBytes/o"; requirement = { - kind = upToNextMinorVersion; - minimumVersion = 0.3.0; + kind = upToNextMajorVersion; + minimumVersion = 1.0.0; }; }; 2937EBC529636D1500BBC0E6 /* XCRemoteSwiftPackageReference "c" */ = { diff --git a/base/base.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/base/base.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 98bb526..511241f 100644 --- a/base/base.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/base/base.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/0xOpenBytes/c", "state" : { - "revision" : "f24cc61b1ca4b72bcc690748232f254771e4d6a8", - "version" : "3.0.0" + "revision" : "e50c296ae2e0cdb9f5032534dfc8e590c7b0cfce", + "version" : "3.0.1" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/0xOpenBytes/o", "state" : { - "revision" : "f0ef1e44a79443782f69b5dcab08bdadcb787faa", - "version" : "0.3.0" + "revision" : "7751d08c5db1c7e4f339289dce1e92b033114ffd", + "version" : "1.0.0" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/0xOpenBytes/t", "state" : { - "revision" : "78294df737c524f40267bca42beb8e10ca28aa41", - "version" : "0.2.0" + "revision" : "f4b8f43622a8b772d995210428dd2b3eb66904cd", + "version" : "1.0.1" } } ], diff --git a/base/base/App/Home/HomeScreen.swift b/base/base/App/Home/HomeScreen.swift index 38e212a..fac0de2 100644 --- a/base/base/App/Home/HomeScreen.swift +++ b/base/base/App/Home/HomeScreen.swift @@ -27,8 +27,8 @@ struct HomeScreen: View { .padding() } ) - Text("Hello, \(settings.user?.username ?? "World")!") } + .navigationTitle("Hello, \(settings.user?.username ?? "World")!") } } diff --git a/base/base/App/Profile/ProfileScreen.swift b/base/base/App/Profile/ProfileScreen.swift index 1bd2c8a..44140dd 100644 --- a/base/base/App/Profile/ProfileScreen.swift +++ b/base/base/App/Profile/ProfileScreen.swift @@ -11,23 +11,26 @@ struct ProfileScreen: View { @ObservedObject var settings: AppSettings = AppSettings.shared var body: some View { - if let user = settings.user { - VStack { - Text("Logged in: \(user.username)") + Group { + if let user = settings.user { + VStack { + Text("Logged in: \(user.username)") - Button( - "Logout", - role: .destructive, - action: { settings.user = nil } + Button( + "Logout", + role: .destructive, + action: { settings.user = nil } + ) + } + } else { + RegisterScreen( + registerViewModel: RegisterViewModel( + registerNetworking: SuccessMockRegisterService() // TODO: (base-Template) Update to Production + ) ) } - } else { - LoginScreen( - registerViewModel: RegisterViewModel( - registerNetworking: SuccessMockRegisterService() // TODO: (base-Template) Update to Production - ) - ) } + .navigationTitle("Profile") } } diff --git a/base/base/App/Profile/Register/RegisterViewModel.swift b/base/base/App/Profile/Register/RegisterViewModel.swift index b60f23b..7faf819 100644 --- a/base/base/App/Profile/Register/RegisterViewModel.swift +++ b/base/base/App/Profile/Register/RegisterViewModel.swift @@ -42,16 +42,16 @@ class RegisterViewModel: ObservableObject { ) await MainActor.run { + AppSettings.shared.user = user + } + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { Navigation.path.toast( title: "Success", message: "You have successfully registered an account.", style: .success ) } - - await MainActor.run { - AppSettings.shared.user = user - } } catch { handle(error: error) } diff --git a/base/base/App/Profile/RegisterFields.swift b/base/base/App/Profile/RegisterFields.swift index 048c152..37e4a03 100644 --- a/base/base/App/Profile/RegisterFields.swift +++ b/base/base/App/Profile/RegisterFields.swift @@ -27,7 +27,7 @@ struct RegisterFields: View { } } -struct RegisterScreen_Previews: PreviewProvider { +struct RegisterFields_Previews: PreviewProvider { static var previews: some View { RegisterFields( username: .constant(""), diff --git a/base/base/App/Profile/LoginScreen.swift b/base/base/App/Profile/RegisterScreen.swift similarity index 93% rename from base/base/App/Profile/LoginScreen.swift rename to base/base/App/Profile/RegisterScreen.swift index 4822de3..3b45e0a 100644 --- a/base/base/App/Profile/LoginScreen.swift +++ b/base/base/App/Profile/RegisterScreen.swift @@ -1,5 +1,5 @@ // -// LoginScreen.swift +// RegisterScreen.swift // base // // Created by Rob Maltese on 12/18/22. @@ -7,7 +7,7 @@ import SwiftUI -struct LoginScreen: View { +struct RegisterScreen: View { @ObservedObject var registerViewModel: RegisterViewModel @FocusState var isFocused: Bool @@ -57,9 +57,9 @@ struct LoginScreen: View { } } -struct LoginScreen_Previews: PreviewProvider { +struct RegisterScreen_Previews: PreviewProvider { static var previews: some View { - LoginScreen( + RegisterScreen( registerViewModel: RegisterViewModel( registerNetworking: SuccessMockRegisterService() ) diff --git a/base/base/App/RootView.swift b/base/base/App/RootView.swift index 13adc9e..218698a 100644 --- a/base/base/App/RootView.swift +++ b/base/base/App/RootView.swift @@ -14,33 +14,35 @@ struct RootView: View { case profile } - @ObservedObject var cartography: CartographyPath - - @State private var selection: Tab = .home + @ObservedObject var navigation: Navigation var body: some View { - CartographyView(path: cartography) { - TabView(selection: $selection) { + TabView(selection: $navigation.tab) { + CartographyView(path: navigation.home) { HomeScreen() - .tag(Tab.home) - .tabItem { - Image(systemName: "house") - Text("Home") - } + } + .tag(Tab.home) + .tabItem { + Image(systemName: "house") + Text("Home") + } + CartographyView(path: navigation.search) { SearchScreen() - .tag(Tab.search) - .tabItem { - Image(systemName: "magnifyingglass") - Text("Search") - } + } + .tag(Tab.search) + .tabItem { + Image(systemName: "magnifyingglass") + Text("Search") + } + CartographyView(path: navigation.profile) { ProfileScreen() - .tag(Tab.profile) - .tabItem { - Image(systemName: "person") - Text("Profile") - } + } + .tag(Tab.profile) + .tabItem { + Image(systemName: "person") + Text("Profile") } } } @@ -48,11 +50,12 @@ struct RootView: View { struct RootView_Previews: PreviewProvider { static var previews: some View { - Navigation.use { nav -> RootView in - nav.isPreview = true - nav.path = CartographyPath() + Navigation.shared.use { navigation -> RootView in + navigation.home = CartographyPath(id: "home.preview") + navigation.search = CartographyPath(id: "search.preview") + navigation.profile = CartographyPath(id: "profile.preview") - return RootView(cartography: Navigation.path) + return RootView(navigation: navigation) } } } diff --git a/base/base/App/Search/SearchScreen.swift b/base/base/App/Search/SearchScreen.swift index 401a75a..a216cdf 100644 --- a/base/base/App/Search/SearchScreen.swift +++ b/base/base/App/Search/SearchScreen.swift @@ -64,6 +64,7 @@ struct SearchScreen: View { Text(date, format: .dateTime) } ) + .navigationTitle("Search") } } diff --git a/base/base/App/Views/Components/ImageView.swift b/base/base/App/Views/Components/ImageView.swift index 2f42053..5112f7f 100644 --- a/base/base/App/Views/Components/ImageView.swift +++ b/base/base/App/Views/Components/ImageView.swift @@ -30,7 +30,7 @@ class ImageViewModel: ObservableObject { do { guard - let data = try await Network.get(url: url).0, + let data = try await Network.get(url: url).data, let imageData = UIImage(data: data) else { return nil } diff --git a/base/base/App/baseApp.swift b/base/base/App/baseApp.swift index da216de..c6430b6 100644 --- a/base/base/App/baseApp.swift +++ b/base/base/App/baseApp.swift @@ -9,11 +9,11 @@ import SwiftUI @main struct OBbaseApp: App { - let navigate: CartographyPath = Navigation.path + @ObservedObject var navigation: Navigation = Navigation.shared var body: some Scene { WindowGroup { - RootView(cartography: navigate) + RootView(navigation: navigation) } } } diff --git a/base/base/Navigation/Implementation/CartographyPath.swift b/base/base/Navigation/Implementation/CartographyPath.swift index f51a6b9..0c5566c 100644 --- a/base/base/Navigation/Implementation/CartographyPath.swift +++ b/base/base/Navigation/Implementation/CartographyPath.swift @@ -8,7 +8,9 @@ import SwiftUI class CartographyPath: ObservableObject { - private static let filename = "CartographyPath" + private static let filePrefix = "CartographyPath" + + let id: String @Published var navigation: NavigationPath @Published var modal: CartographyModal? @@ -16,7 +18,8 @@ class CartographyPath: ObservableObject { @Published var actionSheet: CartographyActionSheet? @Published var toast: CartographyToast? - init(_ codable: NavigationPath.CodableRepresentation? = nil) { + init(id: String, _ codable: NavigationPath.CodableRepresentation? = nil) { + self.id = id if let codable { navigation = NavigationPath(codable) } else { @@ -30,23 +33,27 @@ class CartographyPath: ObservableObject { func save() { guard - Navigation.isPreview == false, + Navigation.shared.isPreview == false, let representation = navigation.codable else { return } do { - try Disk.out(representation, filename: Self.filename) + try Disk.out(representation, filename: Self.name(id: id)) } catch { print(error.localizedDescription) } } - static func load() -> CartographyPath { + static func load(id: String) -> CartographyPath { defer { - try? Disk.delete(filename: filename) + try? Disk.delete(filename: name(id: id)) } - return CartographyPath(try? Disk.in(filename: filename)) + return CartographyPath(id: id, try? Disk.in(filename: name(id: id))) + } + + static func name(id: String) -> String { + "\(filePrefix).\(id)" } } diff --git a/base/base/Navigation/Implementation/CartographyView.swift b/base/base/Navigation/Implementation/CartographyView.swift index 85e5252..3be29db 100644 --- a/base/base/Navigation/Implementation/CartographyView.swift +++ b/base/base/Navigation/Implementation/CartographyView.swift @@ -56,8 +56,7 @@ struct CartographyView: View { extension CartographyView { static func preview(_ content: @escaping () -> RootView) -> CartographyView { - Navigation.isPreview = true - Navigation.path = CartographyPath() + Navigation.shared.isPreview = true return CartographyView(path: Navigation.path, rootView: content) } diff --git a/base/base/Navigation/Implementation/Toast/ToastModifier.swift b/base/base/Navigation/Implementation/Toast/ToastModifier.swift index ab29ae5..0606aba 100644 --- a/base/base/Navigation/Implementation/Toast/ToastModifier.swift +++ b/base/base/Navigation/Implementation/Toast/ToastModifier.swift @@ -7,8 +7,6 @@ import SwiftUI -/// This `ViewModifier` allows us to define the actual view modifier, its animation and interaction within the view. -/// This is built to be applied over any of the content shown, using `ZStack`. struct ToastModifer: ViewModifier { @Binding var toast: CartographyToast? @State private var workItem: DispatchWorkItem? @@ -17,9 +15,8 @@ struct ToastModifer: ViewModifier { content .frame(maxWidth: .infinity, maxHeight: .infinity) .overlay( - ZStack { - toastView() - }.animation(.spring(), value: toast) + toastView() + .animation(.spring(), value: toast) ) .onChange(of: toast) { _ in showToast() diff --git a/base/base/Navigation/Navigation.swift b/base/base/Navigation/Navigation.swift index 67419cb..814b153 100644 --- a/base/base/Navigation/Navigation.swift +++ b/base/base/Navigation/Navigation.swift @@ -5,10 +5,30 @@ // Created by Leif on 12/16/22. // -public enum Navigation { - static var path: CartographyPath = CartographyPath.load() +import SwiftUI - static var isPreview = false +public final class Navigation: ObservableObject { + static var shared: Navigation = Navigation() + + var home: CartographyPath = CartographyPath.load(id: "home") + var search: CartographyPath = CartographyPath.load(id: "search") + var profile: CartographyPath = CartographyPath.load(id: "profile") + + var isPreview = false + + @Published var tab: RootView.Tab = .home + + static var path: CartographyPath { + Navigation.shared.use { navigation in + switch navigation.tab { + case .home: return navigation.home + case .search: return navigation.search + case .profile: return navigation.profile + } + } + } + + private init() { } } -extension Navigation: StaticUsable { } +extension Navigation: Usable { } diff --git a/base/base/Networking/Implementation/AuthNetworking+Default.swift b/base/base/Networking/Implementation/AuthNetworking+Default.swift index f9ecd5b..50fd81b 100644 --- a/base/base/Networking/Implementation/AuthNetworking+Default.swift +++ b/base/base/Networking/Implementation/AuthNetworking+Default.swift @@ -57,7 +57,7 @@ extension AuthNetworking { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .iso8601 - let (data, respone) = try await Network.post( + let dataResponse = try await Network.post( url: baseURL.appendingPathComponent("register"), body: try encoder.encode(payload), headerFields: [ @@ -67,13 +67,13 @@ extension AuthNetworking { ) // Check Response - let httpResponse = respone as? HTTPURLResponse + let httpResponse = dataResponse.response as? HTTPURLResponse guard httpResponse?.statusCode == 200 else { throw AuthError.validation(reason: "Status code was not 200, but was: '\(httpResponse?.statusCode ?? -1)'") } - guard let data = data else { + guard let data = dataResponse.data else { throw AuthError.noData }