Skip to content

Commit

Permalink
refactor: authVm to @observable
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandram-Dutta committed Feb 4, 2024
1 parent 4830f83 commit 7a22b9a
Show file tree
Hide file tree
Showing 78 changed files with 96 additions and 106 deletions.
4 changes: 2 additions & 2 deletions VITTY/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ContentView: View {
@State private var communityPageViewModel = CommunityPageViewModel()
@State private var suggestedFriendsViewModel = SuggestedFriendsViewModel()
@State private var friendRequestViewModel = FriendRequestViewModel()
@StateObject var authState: AuthViewModel = AuthViewModel()
@State var authState: AuthViewModel = AuthViewModel()
@StateObject var timeTableVM: TimetableViewModel = TimetableViewModel()
// @StateObject var localNotificationsManager = NotificationsManager()
// @StateObject var notifVM = NotificationsViewModel()
Expand Down Expand Up @@ -47,7 +47,7 @@ struct ContentView: View {
// ) { _ in
// NotificationsManager.shared.getNotificationSettings()
// }
.environmentObject(authState)
.environment(authState)
.environmentObject(timeTableVM)
// .environmentObject(notifVM)
.environment(communityPageViewModel)
Expand Down
92 changes: 38 additions & 54 deletions VITTY/VITTY.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
5251A7FC2B46E3A800D44CFE /* SwiftFormatConfiguration in Frameworks */ = {isa = PBXBuildFile; productRef = 5251A7FB2B46E3A800D44CFE /* SwiftFormatConfiguration */; };
5251A7FE2B46E3A800D44CFE /* swift-format in Frameworks */ = {isa = PBXBuildFile; productRef = 5251A7FD2B46E3A800D44CFE /* swift-format */; };
525AA7A92B4B0164003C6A12 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AA7A82B4B0164003C6A12 /* SearchView.swift */; };
525FFEF62B6F906C001CAAD3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 525FFEF52B6F906C001CAAD3 /* GoogleService-Info.plist */; };
525FFEF82B6F9072001CAAD3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 525FFEF72B6F9072001CAAD3 /* GoogleService-Info.plist */; };
52A955832B497C7A00CA6EC5 /* FriendTimeTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52A955822B497C7A00CA6EC5 /* FriendTimeTableView.swift */; };
52CC87052B677B110030B7E9 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52CC87042B677B110030B7E9 /* GoogleService-Info.plist */; };
52CC87072B677B160030B7E9 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52CC87062B677B160030B7E9 /* GoogleService-Info.plist */; };
52DBBE882B47B6B30014C57A /* FriendCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DBBE872B47B6B30014C57A /* FriendCard.swift */; };
5D141B052A2658CD005977F8 /* textField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D141B042A2658CD005977F8 /* textField.swift */; };
5D141B0A2A265B15005977F8 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D141B092A265B15005977F8 /* Profile.swift */; };
Expand Down Expand Up @@ -281,9 +281,9 @@
524B843B2B46F6FD006D18BD /* AddFriendsHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFriendsHeader.swift; sourceTree = "<group>"; };
5251A7FF2B46E3C000D44CFE /* .swift-format */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-format"; sourceTree = "<group>"; };
525AA7A82B4B0164003C6A12 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
525FFEF52B6F906C001CAAD3 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
525FFEF72B6F9072001CAAD3 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
52A955822B497C7A00CA6EC5 /* FriendTimeTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendTimeTableView.swift; sourceTree = "<group>"; };
52CC87042B677B110030B7E9 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
52CC87062B677B160030B7E9 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
52DBBE872B47B6B30014C57A /* FriendCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendCard.swift; sourceTree = "<group>"; };
5D141B042A2658CD005977F8 /* textField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = textField.swift; sourceTree = "<group>"; };
5D141B092A265B15005977F8 /* Profile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profile.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -490,9 +490,24 @@
314A408D27383BEC0058082F /* VITTY */ = {
isa = PBXGroup;
children = (
314A40A527383C3F0058082F /* Model */,
5D3D92502A1816CC0013803E /* Username */,
314A40A327383C280058082F /* ViewModel */,
5D141B062A265AF0005977F8 /* Profile */,
5D44FFF72A2A69C70005A1E4 /* SetStatus */,
5D1FF25D2A32637D00B0620A /* Schedule */,
5D1FF25F2A3263CA00B0620A /* SplashScreen */,
5D1FF2612A3263FE00B0620A /* NotificationView */,
5D1FF2632A32643400B0620A /* Settings */,
5D141B032A2658BE005977F8 /* Components */,
5D1FF2662A32653400B0620A /* Instructions */,
5D629B392A3FA5FB000B8E7A /* FriendActivity */,
5DE8C00C2A8FC7B100AE3995 /* FriendCircle */,
5DB03A312A85553800DB7E60 /* SideMenu */,
524B842C2B46EBA6006D18BD /* Home */,
524B84302B46EF07006D18BD /* Circle */,
52DC41DF2B6F8B1500CCF8DB /* Firebase */,
52CC87082B677FCC0030B7E9 /* Auth */,
52CC87012B677AFA0030B7E9 /* Firebase */,
5D3D924F2A1816980013803E /* Core */,
3109637F278227580009A29C /* Services */,
31128CF02772F0210084C9EA /* Info.plist */,
314A40A127383C0A0058082F /* Utilities */,
Expand Down Expand Up @@ -528,13 +543,6 @@
path = ViewModel;
sourceTree = "<group>";
};
314A40A427383C370058082F /* View */ = {
isa = PBXGroup;
children = (
);
path = View;
sourceTree = "<group>";
};
314A40A527383C3F0058082F /* Model */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -800,39 +808,39 @@
path = Views;
sourceTree = "<group>";
};
52CC87012B677AFA0030B7E9 /* Firebase */ = {
52CC87082B677FCC0030B7E9 /* Auth */ = {
isa = PBXGroup;
children = (
52CC87032B677B060030B7E9 /* Prod */,
52CC87022B677B020030B7E9 /* Dev */,
3168511E277319480046A9AC /* SignupOR.swift */,
5D72EDD92AB9906200704BF5 /* Auth */,
31096380278227730009A29C /* AuthService.swift */,
);
path = Firebase;
path = Auth;
sourceTree = "<group>";
};
52CC87022B677B020030B7E9 /* Dev */ = {
52DC41DF2B6F8B1500CCF8DB /* Firebase */ = {
isa = PBXGroup;
children = (
52CC87062B677B160030B7E9 /* GoogleService-Info.plist */,
52DC41E12B6F8B2100CCF8DB /* Prod */,
52DC41E02B6F8B1E00CCF8DB /* Dev */,
);
path = Dev;
path = Firebase;
sourceTree = "<group>";
};
52CC87032B677B060030B7E9 /* Prod */ = {
52DC41E02B6F8B1E00CCF8DB /* Dev */ = {
isa = PBXGroup;
children = (
52CC87042B677B110030B7E9 /* GoogleService-Info.plist */,
525FFEF72B6F9072001CAAD3 /* GoogleService-Info.plist */,
);
path = Prod;
path = Dev;
sourceTree = "<group>";
};
52CC87082B677FCC0030B7E9 /* Auth */ = {
52DC41E12B6F8B2100CCF8DB /* Prod */ = {
isa = PBXGroup;
children = (
3168511E277319480046A9AC /* SignupOR.swift */,
5D72EDD92AB9906200704BF5 /* Auth */,
31096380278227730009A29C /* AuthService.swift */,
525FFEF52B6F906C001CAAD3 /* GoogleService-Info.plist */,
);
path = Auth;
path = Prod;
sourceTree = "<group>";
};
5D141B032A2658BE005977F8 /* Components */ = {
Expand Down Expand Up @@ -965,30 +973,6 @@
path = View;
sourceTree = "<group>";
};
5D3D924F2A1816980013803E /* Core */ = {
isa = PBXGroup;
children = (
524B84302B46EF07006D18BD /* Circle */,
524B842C2B46EBA6006D18BD /* Home */,
5DB03A312A85553800DB7E60 /* SideMenu */,
5DE8C00C2A8FC7B100AE3995 /* FriendCircle */,
5D629B392A3FA5FB000B8E7A /* FriendActivity */,
5D1FF2662A32653400B0620A /* Instructions */,
5D141B032A2658BE005977F8 /* Components */,
5D1FF2632A32643400B0620A /* Settings */,
5D1FF2612A3263FE00B0620A /* NotificationView */,
5D1FF25F2A3263CA00B0620A /* SplashScreen */,
5D1FF25D2A32637D00B0620A /* Schedule */,
5D44FFF72A2A69C70005A1E4 /* SetStatus */,
5D141B062A265AF0005977F8 /* Profile */,
5D3D92502A1816CC0013803E /* Username */,
314A40A527383C3F0058082F /* Model */,
314A40A427383C370058082F /* View */,
314A40A327383C280058082F /* ViewModel */,
);
path = Core;
sourceTree = "<group>";
};
5D3D92502A1816CC0013803E /* Username */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1325,8 +1309,8 @@
31128CF92772F57E0084C9EA /* Poppins-Medium.ttf in Resources */,
31128CFA2772F57E0084C9EA /* Poppins-SemiBoldItalic.ttf in Resources */,
31128CFC2772F57E0084C9EA /* Poppins-Regular.ttf in Resources */,
52CC87052B677B110030B7E9 /* GoogleService-Info.plist in Resources */,
52CC87072B677B160030B7E9 /* GoogleService-Info.plist in Resources */,
525FFEF62B6F906C001CAAD3 /* GoogleService-Info.plist in Resources */,
525FFEF82B6F9072001CAAD3 /* GoogleService-Info.plist in Resources */,
314A409627383BEE0058082F /* Preview Assets.xcassets in Resources */,
314A409327383BEE0058082F /* Assets.xcassets in Resources */,
);
Expand Down
23 changes: 12 additions & 11 deletions VITTY/VITTY/Auth/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ enum LoginOption {
case appleSignin
}

class AuthViewModel: NSObject, ObservableObject {
@Published var loggedInUser: User?
@Published var isAuthenticating: Bool = false
@Published var error: NSError?
@Published var onboardingComplete: Bool = false
@Observable
class AuthViewModel: NSObject {
var loggedInUser: User?
var isAuthenticating: Bool = false
var error: NSError?
var onboardingComplete: Bool = false

@Published var isNewUser: Bool = false
var isNewUser: Bool = false

@Published var myUser: AuthResponse = AuthResponse(
var myUser: AuthResponse = AuthResponse(
name: "",
picture: "",
role: "",
Expand All @@ -37,10 +38,10 @@ class AuthViewModel: NSObject, ObservableObject {
let auth = Auth.auth()
fileprivate var currentNonce: String?

@Published var token: String = ""
@Published var username: String = ""
@Published var name: String = ""
@Published var image: String = ""
var token: String = ""
var username: String = ""
var name: String = ""
var image: String = ""

// MARK: UserDefault keys

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct AddFriendsView: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(SuggestedFriendsViewModel.self) private var suggestedFriendsViewModel
@Environment(FriendRequestViewModel.self) private var friendRequestViewModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SwiftUI

struct FriendReqCard: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(FriendRequestViewModel.self) private var friendRequestViewModel

let friend: Friend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct FriendRequestView: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(FriendRequestViewModel.self) private var friendRequestViewModel

var body: some View {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct SearchView: View {
@State private var searchText = ""
@State private var searchedFriends = [Friend]()
@State private var loading = false
@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(\.dismiss) var dismiss
var body: some View {
Group {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct AddFriendCard: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(SuggestedFriendsViewModel.self) private var suggestedFriendsViewModel

let friend: Friend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct SuggestedFriendsView: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(SuggestedFriendsViewModel.self) private var suggestedFriendsViewModel

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct CommunityPage: View {

@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@EnvironmentObject private var timeTableViewModel: TimetableViewModel
@Environment(CommunityPageViewModel.self) private var communityPageViewModel
@State private var friend: Friend? = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct CommunityPageHeader: View {
@State private var isAddFriendsViewPresented = false
@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(FriendRequestViewModel.self) private var friendRequestViewModel
@Environment(CommunityPageViewModel.self) private var communityPageViewModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct FriendTimeTableView: View {

@Environment(\.dismiss) var dismiss
@EnvironmentObject var timetableViewModel: TimetableViewModel
@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Environment(CommunityPageViewModel.self) private var communityPageViewModel
@State var tabSelected: Int = Date.convertToMondayWeek()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct LogoutPopup: View {
@EnvironmentObject var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@Binding var showLogout: Bool
var cornerRadius = 3.0
var fontSizeButton = 14.0
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct FriendCircle: View {
@EnvironmentObject var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState

@Environment(\.presentationMode) var presentationMode
@State var text: String = ""
Expand Down Expand Up @@ -54,7 +54,7 @@ struct FriendCircle: View {
SuggestionsView()
.tag(Tabs.suggestions)
RequestsView()
.environmentObject(authState)
.environment(authState)
.environmentObject(vm)
.tag(Tabs.requests)
FriendsView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct RequestsView: View {
@EnvironmentObject private var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
@EnvironmentObject private var vm: FriendCircleViewModel

var body: some View {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct InstructionsCards: View {
@EnvironmentObject var authState: AuthViewModel
@Environment(AuthViewModel.self) private var authState
var body: some View {
VStack {
ZStack(alignment: .leading) {
Expand Down
Loading

0 comments on commit 7a22b9a

Please sign in to comment.