Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Friese <peter@peterfriese.de>
  • Loading branch information
peterfriese committed Nov 19, 2024
1 parent 487de6b commit 3f5a140
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,13 @@ import SwiftUI

@main
struct FriendlyFlixApp: App {
private func loadRocketSimConnect() {
#if DEBUG
guard Bundle(
path: "/Applications/RocketSim.app/Contents/Frameworks/RocketSimConnectLinker.nocache.framework"
)?
.load() == true else {
print("Failed to load linker framework")
return
}
print("RocketSim Connect successfully linked")
#endif
}

var authenticationService: AuthenticationService?

init() {
loadRocketSimConnect()
FirebaseApp.configure()

authenticationService = AuthenticationService()
authenticationService?.onSignUp { user in
print(
"User signed in \(user.displayName ?? "(no fullname)") with email \(user.email ?? "(no email)")"
)
let userName = String(user.email?.split(separator: "@").first ?? "(unknown)")
Task {
try await DataConnect.friendlyFlixConnector.upsertUserMutation.execute(username: userName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import AuthenticationServices
import SwiftUI
import os

private enum FocusableField: Hashable {
case email
Expand All @@ -27,6 +28,7 @@ private enum AuthenticationFlow {
}

struct AuthenticationScreen: View {
private let logger = Logger(subsystem: "FriendlyFlix", category: "auth")
@Environment(AuthenticationService.self) var authenticationService
@Environment(\.colorScheme) private var colorScheme
@Environment(\.dismiss) private var dismiss
Expand Down Expand Up @@ -61,7 +63,7 @@ struct AuthenticationScreen: View {
try await authenticationService.signInWithEmailPassword(email: email, password: password)
dismiss()
} catch {
print(error.localizedDescription)
logger.error("Error when signing in with email / password: \(error.localizedDescription)")
errorMessage = error.localizedDescription
}
}
Expand All @@ -74,7 +76,7 @@ struct AuthenticationScreen: View {
errorMessage = ""
dismiss()
} catch {
print(error.localizedDescription)
logger.error("Error when signing up with email / password: \(error.localizedDescription)")
errorMessage = error.localizedDescription
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import FirebaseAuth
import Foundation
import Observation
import os

enum AuthenticationState {
case unauthenticated
Expand All @@ -24,6 +25,8 @@ enum AuthenticationState {

@Observable
class AuthenticationService {
private let logger = Logger(subsystem: "FriendlyFlix", category: "auth")

var presentingAuthenticationDialog = false
var presentingAccountDialog = false

Expand Down Expand Up @@ -57,6 +60,7 @@ class AuthenticationService {
try await Auth.auth().createUser(withEmail: email, password: password)

if let onSignUp, let user = Auth.auth().currentUser {
logger.debug("User signed in \(user.displayName ?? "(no fullname)") with email \(user.email ?? "(no email)")")
onSignUp(user)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import FirebaseDataConnect
import FriendlyFlixSDK
import NukeUI
import SwiftUI
import os

struct MovieCardView: View {
private let logger = Logger(subsystem: "FriendlyFlix", category: "moviecard")
@Environment(\.dismiss) private var dismiss
private var connector = DataConnect.friendlyFlixConnector

Expand All @@ -32,7 +34,6 @@ struct MovieCardView: View {
}

// MARK: - Favourite handling

private let isFavouriteRef: QueryRefObservation<
GetIfFavoritedMovieQuery.Data,
GetIfFavoritedMovieQuery.Variables
Expand Down Expand Up @@ -132,7 +133,7 @@ extension MovieCardView {
do {
let _ = try await isFavouriteRef.execute()
} catch {
print(error)
logger.error("Error when trying to fetch favourite status: \(error.localizedDescription)")
}
}
}
Expand Down

0 comments on commit 3f5a140

Please sign in to comment.