Skip to content

Commit

Permalink
πŸ› Bug(#14): μƒν’ˆ 등둝 ν›„ 둜그인 μƒνƒœκ°€ μœ μ§€λ˜μ§€ μ•ŠλŠ” 버그 μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
joho2022 committed Jun 26, 2024
1 parent fc32580 commit 282c8f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions secondhand/secondhand/Data/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import os

class AppState: ObservableObject {
@Published var realm: Realm?
@Published var userManager: UserManager?
private var app: App

init() {
self.app = App(id: "application-0-fahelom")
let realmManager = RealmManager(realm: nil)
self.userManager = UserManager(realmManager: realmManager)
login()
}

Expand Down Expand Up @@ -71,6 +74,10 @@ class AppState: ObservableObject {
print("Successfully updated subscriptions")
DispatchQueue.main.async {
self.realm = realm
if let userManager = self.userManager {
let realmManager = RealmManager(realm: realm)
userManager.updateRealmManager(realmManager)
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion secondhand/secondhand/User/UserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class UserManager: ObservableObject, UserProvider, UserLoginProvider, UserUpdate
$user
}

private let realmManager: RealmManager
private var realmManager: RealmManager

init(realmManager: RealmManager) {
self.realmManager = realmManager
}

func updateRealmManager(_ realmManager: RealmManager) {
self.realmManager = realmManager
refreshUser()
}

private func refreshUser() {
if let username = user?.username {
self.user = realmManager.fetchUser(by: username)
Expand Down
4 changes: 1 addition & 3 deletions secondhand/secondhand/secondhandApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ struct secondhandApp: App {

var body: some Scene {
WindowGroup {
if let realm = appState.realm {
let realmManager = RealmManager(realm: realm)
let userManager = UserManager(realmManager: realmManager)
if appState.realm != nil, let userManager = appState.userManager {
ContentView()
.environmentObject(userManager)
.environmentObject(productManager)
Expand Down

0 comments on commit 282c8f2

Please sign in to comment.