Skip to content
Merged
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
11 changes: 9 additions & 2 deletions Uplift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
89599A502BD4B4B600DA44DE /* FitnessClassInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89599A4F2BD4B4B600DA44DE /* FitnessClassInstance.swift */; };
896500DC2BB4D33500D822AB /* ClassDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 896500DB2BB4D33500D822AB /* ClassDetailView.swift */; };
897703662BA2028D00F9992F /* ClassesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 897703652BA2028D00F9992F /* ClassesViewModel.swift */; };
897DF9BA2CCDC49B00246B0D /* UpliftAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 897DF9B92CCDC49B00246B0D /* UpliftAPI */; };
89950D8A2B992E8400DFB007 /* ClassesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89950D892B992E8400DFB007 /* ClassesView.swift */; };
8996FEE02BDF351800F13C67 /* NextSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8996FEDF2BDF351800F13C67 /* NextSessionCell.swift */; };
89C8658D2BB4779C00758337 /* ClassCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89C8658C2BB4779C00758337 /* ClassCell.swift */; };
Expand Down Expand Up @@ -195,6 +196,7 @@
2E090ECB2B12FF5900BAE982 /* UpliftAPI in Frameworks */,
2E45B2452B4F632700FB83B7 /* FirebaseAnalytics in Frameworks */,
2E39D82F2B3BCBA400AD238B /* UpliftAPI in Frameworks */,
897DF9BA2CCDC49B00246B0D /* UpliftAPI in Frameworks */,
2E2748D22BCD4EC00023882E /* UpliftAPI in Frameworks */,
63A7ABCD2B86B971008D58FB /* UpliftAPI in Frameworks */,
2E45B2402B4E361100FB83B7 /* FirebaseCrashlytics in Frameworks */,
Expand Down Expand Up @@ -522,6 +524,7 @@
636E3D402BBE1EB100B6EFFC /* UpliftAPI */,
636E3D432BBE1F3800B6EFFC /* UpliftAPI */,
2E2748D12BCD4EC00023882E /* UpliftAPI */,
897DF9B92CCDC49B00246B0D /* UpliftAPI */,
);
productName = Uplift;
productReference = 2E8FE38C2B1278B700B3DC6A /* Uplift.app */;
Expand Down Expand Up @@ -561,7 +564,7 @@
2E6785BA2B3A48D700DD3ADA /* XCRemoteSwiftPackageReference "WrappingHStack" */,
2EC3EE642B3C000E00E927BF /* XCRemoteSwiftPackageReference "Kingfisher" */,
2E45B23E2B4E361100FB83B7 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
8996520A2C9A628600354E42 /* XCLocalSwiftPackageReference "UpliftAPI" */,
897DF9B82CCDC49B00246B0D /* XCLocalSwiftPackageReference "UpliftAPI" */,
);
productRefGroup = 2E8FE38D2B1278B700B3DC6A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1010,7 +1013,7 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
8996520A2C9A628600354E42 /* XCLocalSwiftPackageReference "UpliftAPI" */ = {
897DF9B82CCDC49B00246B0D /* XCLocalSwiftPackageReference "UpliftAPI" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = UpliftAPI;
};
Expand Down Expand Up @@ -1118,6 +1121,10 @@
isa = XCSwiftPackageProductDependency;
productName = UpliftAPI;
};
897DF9B92CCDC49B00246B0D /* UpliftAPI */ = {
isa = XCSwiftPackageProductDependency;
productName = UpliftAPI;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 2E8FE3842B1278B700B3DC6A /* Project object */;
Expand Down
20 changes: 8 additions & 12 deletions Uplift/Services/Networking/UserMutations.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
fragment userFields on User {
id
instagram
email
name
netId
giveaways {
id
name
}
}


fragment giveawayFields on Giveaway {
id
name
Expand All @@ -17,20 +17,16 @@ fragment giveawayFields on Giveaway {
}
}

mutation CreateUser($instagram: String, $netId: String!) {
createUser(instagram: $instagram, netId: $netId) {
user {
...userFields
}
mutation CreateUser($email: String!, $name: String!, $netId: String!) {
createUser(email: $email, name: $name, netId: $netId) {
...userFields
}
}

mutation EnterGiveaway($giveawayId: Int!, $userNetId: String!) {
enterGiveaway(giveawayId: $giveawayId, userNetId: $userNetId) {
giveawayInstance {
id
userId
numEntries
}
id
userId
numEntries
}
}
54 changes: 22 additions & 32 deletions Uplift/ViewModels/ClassesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ extension ClassesView {
guard let self else { return }

let gyms: [Gym] = gymFields.map { Gym(from: $0) }
let classes: [FitnessClassInstance] = gyms.flatMap { $0.classes }

self.classes = classes
self.classes = gyms.flatMap { $0.classes }
}
.store(in: &queryBag)
}
Expand All @@ -62,35 +60,32 @@ extension ClassesView {
guard let classes = classes,
let selectedDate = determineDayOfMonth(selectedDay, weeksFromCurr) else { return [] }

return classes.sorted {
guard let lhsDate = toDate($0.startTime),
let rhsDate = toDate($1.startTime) else { return false }
return lhsDate < rhsDate
}
.filter {
if let date = toDate($0.startTime) {
return date.isSameDay(selectedDate)
return classes
.filter { toDate($0.startTime)?.isSameDay(selectedDate) == true }
.sorted {
guard let lhsDate = toDate($0.startTime),
let rhsDate = toDate($1.startTime) else { return false }
return lhsDate < rhsDate
}
return false
}
}

/// The array of next sessions for this class.
func nextSessions(classInstance: FitnessClassInstance) -> [FitnessClassInstance] {
guard let classes = classes else { return [] }

return classes.sorted {
guard let lhsDate = toDate($0.startTime),
let rhsDate = toDate($1.startTime) else { return false }
return lhsDate < rhsDate
}
.filter {
if let date = toDate($0.startTime),
let selectedDate = toDate(classInstance.startTime) {
return date > selectedDate && $0.classId == classInstance.classId
guard let classes = classes,
let selectedDate = toDate(classInstance.startTime) else { return [] }

return classes
.filter {
if let date = toDate($0.startTime) {
return date > selectedDate && $0.classId == classInstance.classId
}
return false
}
.sorted {
guard let lhsDate = toDate($0.startTime),
let rhsDate = toDate($1.startTime) else { return false }
return lhsDate < rhsDate
}
return false
}
}

/// Determine the day of the month for the given weekday. `Nil` if the calendar date is invalid.
Expand Down Expand Up @@ -131,12 +126,7 @@ extension ClassesView {
guard let classes = classes,
let thisDate = determineDayOfMonth(weekday, weeksFromCurr) else { return false }

return classes.contains {
if let date = toDate($0.startTime) {
return date.isSameDay(thisDate)
}
return false
}
return classes.contains { toDate($0.startTime)?.isSameDay(thisDate) == true }
}

}
Expand Down
6 changes: 4 additions & 2 deletions Uplift/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ extension MainView {
// Make lowercase and remove whitespace
netID = netID.lowercased().replacingOccurrences(of: " ", with: "")

// TODO: Update for next giveaway
Network.client.mutationPublisher(
mutation: CreateUserMutation(
instagram: GraphQLNullable(stringLiteral: instagram),
email: "",
name: "",
netId: netID
)
)
.compactMap(\.data?.createUser?.user?.netId)
.compactMap(\.data?.createUser?.netId)
.sink { completion in
if case let .failure(error) = completion {
callback() // If user already created (error thrown), still enter giveaway
Expand Down
2 changes: 1 addition & 1 deletion Uplift/Views/ClassesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ClassesView: View {

private var scrollContent: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack {
LazyVStack {
calendarView
classesOnDay
}
Expand Down