Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/yash/caching #173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ALUM/ALUM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@
80210ECA29BA82E7008B912A /* MenteeProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80210EC929BA82E7008B912A /* MenteeProfileViewModel.swift */; };
80210ECC29BA9EBC008B912A /* MentorCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80210ECB29BA9EBC008B912A /* MentorCard.swift */; };
80210ED429C3DBD9008B912A /* FirebaseAuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80210ED329C3DBD9008B912A /* FirebaseAuthenticationService.swift */; };
8025F8042AF229B300723C7D /* UserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8025F8032AF229B300723C7D /* UserModel.swift */; };
8025F8062AF22F6F00723C7D /* MenteeHomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8025F8052AF22F6F00723C7D /* MenteeHomeViewModel.swift */; };
80274FF5299DB03900CCB9D0 /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80274FF4299DB03900CCB9D0 /* LoginViewModel.swift */; };
8041161E29B21BB800529936 /* MentorProfileScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8041161D29B21BB800529936 /* MentorProfileScreen.swift */; };
8045EEB129F6844B00BD179C /* ServiceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8045EEB029F6844A00BD179C /* ServiceHelper.swift */; };
804AE4AD297B1DA4000B08F2 /* FilledInButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 804AE4AC297B1DA4000B08F2 /* FilledInButtonStyle.swift */; };
805CF73329B7DFBD0081F89E /* MentorProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 805CF73229B7DFBD0081F89E /* MentorProfileViewModel.swift */; };
8071E52D2A044E2900BD11A3 /* CurrentUserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8071E52C2A044E2900BD11A3 /* CurrentUserModel.swift */; };
807ACD412AE21B4200015316 /* HomePage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807ACD402AE21B4200015316 /* HomePage.swift */; };
807ACD432AE21E1F00015316 /* MentorHomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807ACD422AE21E1F00015316 /* MentorHomeViewModel.swift */; };
8083E73329E0D08400033F22 /* RenderTags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8083E73229E0D08400033F22 /* RenderTags.swift */; };
8095FE6E29E1F968006AA63C /* NavigationFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8095FE6D29E1F968006AA63C /* NavigationFooter.swift */; };
8095FE7029E20C89006AA63C /* WhyPairedComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8095FE6F29E20C89006AA63C /* WhyPairedComponent.swift */; };
Expand Down Expand Up @@ -218,12 +222,16 @@
80210EC929BA82E7008B912A /* MenteeProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenteeProfileViewModel.swift; sourceTree = "<group>"; };
80210ECB29BA9EBC008B912A /* MentorCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorCard.swift; sourceTree = "<group>"; };
80210ED329C3DBD9008B912A /* FirebaseAuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseAuthenticationService.swift; sourceTree = "<group>"; };
8025F8032AF229B300723C7D /* UserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserModel.swift; sourceTree = "<group>"; };
8025F8052AF22F6F00723C7D /* MenteeHomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenteeHomeViewModel.swift; sourceTree = "<group>"; };
80274FF4299DB03900CCB9D0 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
8041161D29B21BB800529936 /* MentorProfileScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorProfileScreen.swift; sourceTree = "<group>"; };
8045EEB029F6844A00BD179C /* ServiceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceHelper.swift; sourceTree = "<group>"; };
804AE4AC297B1DA4000B08F2 /* FilledInButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilledInButtonStyle.swift; sourceTree = "<group>"; };
805CF73229B7DFBD0081F89E /* MentorProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorProfileViewModel.swift; sourceTree = "<group>"; };
8071E52C2A044E2900BD11A3 /* CurrentUserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentUserModel.swift; sourceTree = "<group>"; };
807ACD402AE21B4200015316 /* HomePage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePage.swift; sourceTree = "<group>"; };
807ACD422AE21E1F00015316 /* MentorHomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorHomeViewModel.swift; sourceTree = "<group>"; };
8083E73229E0D08400033F22 /* RenderTags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderTags.swift; sourceTree = "<group>"; };
8095FE6D29E1F968006AA63C /* NavigationFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationFooter.swift; sourceTree = "<group>"; };
8095FE6F29E20C89006AA63C /* WhyPairedComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhyPairedComponent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -484,6 +492,7 @@
97992B5E29A6E81D00701CC7 /* SignUpModel.swift */,
979303D729E87E0E0053C30E /* SessionModel.swift */,
8071E52C2A044E2900BD11A3 /* CurrentUserModel.swift */,
8025F8032AF229B300723C7D /* UserModel.swift */,
);
path = Models;
sourceTree = "<group>";
Expand All @@ -495,6 +504,7 @@
07ECF5F82A22A94A0093C37B /* PostSessionForm */,
07E885342A19F0B800B7AD27 /* Routers */,
0799ACF12A01109000EEAFA2 /* LoginReviewPage.swift */,
807ACD402AE21B4200015316 /* HomePage.swift */,
97A31AC729BAFA7600B79D30 /* PreSessionForm */,
97A2FE8B2989C20900405FD6 /* LoginScreen.swift */,
8041161D29B21BB800529936 /* MentorProfileScreen.swift */,
Expand All @@ -515,6 +525,8 @@
children = (
0757553929FAA380008E73FB /* QuestionViewModel.swift */,
805CF73229B7DFBD0081F89E /* MentorProfileViewModel.swift */,
807ACD422AE21E1F00015316 /* MentorHomeViewModel.swift */,
8025F8052AF22F6F00723C7D /* MenteeHomeViewModel.swift */,
80210EC929BA82E7008B912A /* MenteeProfileViewModel.swift */,
80274FF4299DB03900CCB9D0 /* LoginViewModel.swift */,
97EB2BB129B5C63B001988D9 /* SignUpViewModel.swift */,
Expand Down Expand Up @@ -816,6 +828,8 @@
804AE4AD297B1DA4000B08F2 /* FilledInButtonStyle.swift in Sources */,
0757552429FAA2AB008E73FB /* MultipleChoiceList.swift in Sources */,
07CA49972A1C53DA00A81153 /* ALUMText.swift in Sources */,
8025F8042AF229B300723C7D /* UserModel.swift in Sources */,
807ACD412AE21B4200015316 /* HomePage.swift in Sources */,
0757553029FAA2D6008E73FB /* PreSessionConfirmationScreen.swift in Sources */,
0726C9EF29DC4B120042A486 /* CustomErrors.swift in Sources */,
E3F4186629E7246400FDE56D /* CalendlyBooking.swift in Sources */,
Expand All @@ -833,6 +847,7 @@
8095FE6E29E1F968006AA63C /* NavigationFooter.swift in Sources */,
0757551F29FAA2AB008E73FB /* DynamicProgressBarComponent.swift in Sources */,
97E439FA29AD98BB00F0B7C1 /* SignUpGradeComponent.swift in Sources */,
8025F8062AF22F6F00723C7D /* MenteeHomeViewModel.swift in Sources */,
8045EEB129F6844B00BD179C /* ServiceHelper.swift in Sources */,
97EB2BB229B5C63B001988D9 /* SignUpViewModel.swift in Sources */,
07ECF5F72A2279940093C37B /* PostSessionFormRouter.swift in Sources */,
Expand Down Expand Up @@ -870,6 +885,7 @@
80210ECC29BA9EBC008B912A /* MentorCard.swift in Sources */,
0793B4222A19FA7200AF78C8 /* CustomNavBarPreferenceKeys.swift in Sources */,
80210EC529BA8255008B912A /* MenteeProfileScreen.swift in Sources */,
807ACD432AE21E1F00015316 /* MentorHomeViewModel.swift in Sources */,
0748208F29712921004AF547 /* ALUMApp.swift in Sources */,
80210EBD29B95D50008B912A /* ProfileModel.swift in Sources */,
97A2FE8C2989C20900405FD6 /* LoginScreen.swift in Sources */,
Expand Down
9 changes: 7 additions & 2 deletions ALUM/ALUM/Models/CurrentUserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@Published var showInternalError: Bool
@Published var showNetworkError: Bool
@Published var errorMessage: String?

Check failure on line 28 in ALUM/ALUM/Models/CurrentUserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
@Published var mentorObj: MentorObject
@Published var menteeObj: MenteeObject

@Published var sessionId: String?
@Published var pairedMentorId: String?
Expand All @@ -39,6 +42,8 @@
self.showTabBar = true
self.showInternalError = false
self.showNetworkError = false
self.mentorObj = MentorObject()
self.menteeObj = MenteeObject()
}

/// Since async operations are involved, this function will limit updating the current
Expand Down Expand Up @@ -126,7 +131,7 @@
self.pairedMentorId = userPairedMentorId
}
} else if self.role == .mentor {
guard let userPairedMenteeId = userData.pairedMenteeId else {
guard let userPairedMenteeId = userData.pairedIds?[0] else {
DispatchQueue.main.async {
CurrentUserModel.shared.showInternalError.toggle()
}
Expand All @@ -139,7 +144,7 @@
}

DispatchQueue.main.async {
self.sessionId = userData.sessionId
self.sessionId = userData.upcomingSessionId
}
}

Expand Down
26 changes: 26 additions & 0 deletions ALUM/ALUM/Models/UserModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// UserModel.swift
// ALUM
//
// Created by Yash Ravipati on 10/31/23.
//

import Foundation

struct MenteeObject {
var MenteeProfile: MenteeInfo?

Check failure on line 11 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MenteeProfile' should start with a lowercase character (identifier_name)
var HomeData: SelfGetData?

Check failure on line 12 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HomeData' should start with a lowercase character (identifier_name)
init(MenteeProfile: MenteeInfo? = nil, HomeData: SelfGetData? = nil) {

Check failure on line 13 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MenteeProfile' should start with a lowercase character (identifier_name)

Check failure on line 13 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HomeData' should start with a lowercase character (identifier_name)
self.MenteeProfile = MenteeProfile
self.HomeData = HomeData
}
}

struct MentorObject {
var MentorProfile: MentorInfo?

Check failure on line 20 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MentorProfile' should start with a lowercase character (identifier_name)
var HomeData: SelfGetData?

Check failure on line 21 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HomeData' should start with a lowercase character (identifier_name)
init(MentorProfile: MentorInfo? = nil, HomeData: SelfGetData? = nil) {

Check failure on line 22 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'MentorProfile' should start with a lowercase character (identifier_name)

Check failure on line 22 in ALUM/ALUM/Models/UserModel.swift

View workflow job for this annotation

GitHub Actions / lint

Identifier Name Violation: Variable name 'HomeData' should start with a lowercase character (identifier_name)
self.MentorProfile = MentorProfile
self.HomeData = HomeData
}
}
13 changes: 10 additions & 3 deletions ALUM/ALUM/Services/UserService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ struct MentorPostData: Codable {

struct SelfGetData: Decodable {
var status: String
var sessionId: String?
var name: String
var pastSessionId: String
var upcomingSessionId: String
var menteeNames: [String]?
var mentorName: [String]?
var mentorMajor: String?
var mentorUniversity: String?
var mentorCareer: String?
var pairedMentorId: String?
var pairedMenteeId: String?
var pairedIds: [String]?
}

struct MenteeGetData: Decodable {
Expand All @@ -64,7 +71,7 @@ class UserService {
try JSONDecoder().decode(SelfGetData.self, from: responseData)
})

print("SUCCESS - \(route.label) - \(userData.pairedMenteeId) - \(userData.pairedMentorId)")
print("SUCCESS - \(route.label) - \(String(describing: userData.pairedIds)) - \(String(describing: userData.pairedMentorId))")
return userData
}

Expand Down
31 changes: 31 additions & 0 deletions ALUM/ALUM/ViewModels/MenteeHomeViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MenteeHomeViewModel.swift
// ALUM
//
// Created by Yash Ravipati on 11/1/23.
//

import Foundation
import SwiftUI

final class MenteeHomeViewModel: ObservableObject {
@ObservedObject var currentUser: CurrentUserModel = CurrentUserModel.shared

@Published var mentee: SelfGetData?

func getMenteeHome() async throws {
guard let menteeHomeData = try? await UserService.shared.getSelf() else {
print("Error getting info")
return
}

DispatchQueue.main.async {
self.mentee = menteeHomeData
self.currentUser.menteeObj.HomeData = menteeHomeData
}
}

func isLoading() -> Bool {
return mentee == nil
}
}
1 change: 1 addition & 0 deletions ALUM/ALUM/ViewModels/MenteeProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class MenteeProfileViewmodel: ObservableObject {
DispatchQueue.main.async {
self.mentee = menteeData.mentee
self.selfView = self.currentUser.uid == menteeData.mentee.id
self.currentUser.menteeObj.MenteeProfile = menteeData.mentee
}
}

Expand Down
31 changes: 31 additions & 0 deletions ALUM/ALUM/ViewModels/MentorHomeViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MentorHomeViewModel.swift
// ALUM
//
// Created by Yash Ravipati on 10/19/23.
//

import Foundation
import SwiftUI

final class MentorHomeViewModel: ObservableObject {
@ObservedObject var currentUser: CurrentUserModel = CurrentUserModel.shared

@Published var mentor: SelfGetData?

func getMentorHome() async throws {
guard let mentorHomeData = try? await UserService.shared.getSelf() else {
print("Error getting info")
return
}

DispatchQueue.main.async {
self.mentor = mentorHomeData
self.currentUser.mentorObj.HomeData = mentorHomeData
}
}

func isLoading() -> Bool {
return mentor == nil
}
}
1 change: 1 addition & 0 deletions ALUM/ALUM/ViewModels/MentorProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class MentorProfileViewModel: ObservableObject {
DispatchQueue.main.async {
self.mentor = mentorData.mentor
self.selfView = self.currentUser.uid == mentorData.mentor.id
self.currentUser.mentorObj.MentorProfile = mentorData.mentor
}
} catch {
print("An error occurred: \(error)")
Expand Down
1 change: 0 additions & 1 deletion ALUM/ALUM/Views/LoginScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import SwiftUI
import Firebase

struct LoginScreen: View {
@ObservedObject var currentUser: CurrentUserModel = CurrentUserModel.shared
Expand Down
28 changes: 15 additions & 13 deletions ALUM/ALUM/Views/MenteeProfileScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
.padding(.top, 0)
}
}.onAppear(perform: {
Task {
do {
try await viewModel.fetchMenteeInfo(userID: uID)
} catch {
print("Error")
if (currentUser.menteeObj.MenteeProfile == nil){

Check failure on line 28 in ALUM/ALUM/Views/MenteeProfileScreen.swift

View workflow job for this annotation

GitHub Actions / lint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
Task {
do {
try await viewModel.fetchMenteeInfo(userID: uID)
} catch {
print("Error")
}
}
}
})
}

var content: some View {
let mentee = viewModel.mentee!
let mentee = currentUser.menteeObj.MenteeProfile!

return
GeometryReader { grr in
Expand Down Expand Up @@ -109,7 +111,7 @@
}
.padding(.top, 57)
}
Text(viewModel.mentee!.name)
Text(currentUser.menteeObj.MenteeProfile!.name)
.font(Font.custom("Metropolis-Regular", size: 34, relativeTo: .largeTitle))
}
}
Expand All @@ -119,7 +121,7 @@
Image(systemName: "graduationcap")
.frame(width: 25.25, height: 11)
.foregroundColor(Color("ALUM Primary Purple"))
Text(String(viewModel.mentee!.grade) + "th Grade @ NHS")
Text(String(currentUser.menteeObj.MenteeProfile!.grade) + "th Grade @ NHS")
.font(Font.custom("Metropolis-Regular", size: 17, relativeTo: .headline))
}
.padding(.bottom, 18)
Expand All @@ -129,16 +131,16 @@
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.leading, 16)
.padding(.bottom, 8)
Text(viewModel.mentee!.about )
Text(currentUser.menteeObj.MenteeProfile!.about )
.font(Font.custom("Metropolis-Regular", size: 17, relativeTo: .headline))
.lineSpacing(5)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 16)
.padding(.bottom, 32)
RenderTags(tags: viewModel.mentee!.careerInterests, title: "Career Interests")
RenderTags(tags: currentUser.menteeObj.MenteeProfile!.careerInterests, title: "Career Interests")
.padding(.leading, 16)
.padding(.bottom, 8)
RenderTags(tags: viewModel.mentee!.topicsOfInterest, title: "Topics of Interest")
RenderTags(tags: currentUser.menteeObj.MenteeProfile!.topicsOfInterest, title: "Topics of Interest")
.padding(.leading, 16)
.padding(.bottom, 8)
}
Expand All @@ -155,7 +157,7 @@
.padding(.bottom, 8)
CustomNavLink(destination:
MentorProfileScreen(
uID: viewModel.mentee!.mentorId ?? ""
uID: currentUser.menteeObj.MenteeProfile!.mentorId ?? ""
)
.onAppear(perform: {
currentUser.showTabBar = false
Expand All @@ -165,7 +167,7 @@
})
.customNavigationTitle("Mentor Profile")
) {
MentorCard(isEmpty: true, uID: viewModel.mentee!.mentorId ?? "")
MentorCard(isEmpty: true, uID: currentUser.menteeObj.MenteeProfile!.mentorId ?? "")
.padding(.bottom, 10)
}
}
Expand Down
Loading
Loading