Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions Uplift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
2EE5F3E42B12EDB6008E0299 /* ApolloAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 2EE5F3E32B12EDB6008E0299 /* ApolloAPI */; };
2EF1A2582B129EEB007A299F /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EF1A2572B129EEB007A299F /* Network.swift */; };
842FB0CCD71C3202DE5836F1 /* Pods_Uplift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E86AC23F1B9AFB11552390BF /* Pods_Uplift.framework */; };
89921C392B8A98BA00364400 /* HomeGymCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89921C382B8A98BA00364400 /* HomeGymCellViewModel.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -145,6 +146,7 @@
2EE5F3C92B12E34D008E0299 /* Apollo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Apollo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2EF1A2572B129EEB007A299F /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
61B508C772C15943F0FDB2E8 /* Pods-Uplift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Uplift.debug.xcconfig"; path = "Target Support Files/Pods-Uplift/Pods-Uplift.debug.xcconfig"; sourceTree = "<group>"; };
89921C382B8A98BA00364400 /* HomeGymCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeGymCellViewModel.swift; sourceTree = "<group>"; };
D6EB08EC41E957E55D918532 /* Pods-Uplift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Uplift.release.xcconfig"; path = "Target Support Files/Pods-Uplift/Pods-Uplift.release.xcconfig"; sourceTree = "<group>"; };
E86AC23F1B9AFB11552390BF /* Pods_Uplift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Uplift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -257,6 +259,7 @@
2E39D82B2B3BB35000AD238B /* FacilityExpandedViewModel.swift */,
2E39D8232B3B66FD00AD238B /* FitnessCenterViewModel.swift */,
2E6785C12B3A5CE000DD3ADA /* GymDetailViewModel.swift */,
89921C382B8A98BA00364400 /* HomeGymCellViewModel.swift */,
2E1105BE2B13B0E100119F5B /* HomeViewModel.swift */,
);
path = ViewModels;
Expand Down Expand Up @@ -680,6 +683,7 @@
2E15F4E62B391E5300414BEC /* Array+Extension.swift in Sources */,
2E45B2472B4F643500FB83B7 /* AnalyticsManager.swift in Sources */,
2E39D8202B3B623B00AD238B /* FitnessCenterView.swift in Sources */,
89921C392B8A98BA00364400 /* HomeGymCellViewModel.swift in Sources */,
2E1105C22B13D15100119F5B /* HomeGymCell.swift in Sources */,
2E15F4F92B3950F800414BEC /* Date+Extension.swift in Sources */,
2E8FE3902B1278B700B3DC6A /* UpliftApp.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions Uplift/ViewModels/GymDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ extension GymDetailView {
}
}

/// Determine whether at least one fitness center is open at this `Gym`.
func fitnessCenterIsOpen(gym: Gym) -> Bool {
gym.fitnessCenters.allSatisfy {
switch $0.status {
case .closed:
return false
default:
return true
}
}
}

}

}
79 changes: 79 additions & 0 deletions Uplift/ViewModels/HomeGymCellViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// HomeGymCellViewModel.swift
// Uplift
//
// Created by Caitlyn Jin on 2/24/24.
// Copyright © 2024 Cornell AppDev. All rights reserved.
//

import SwiftUI

extension HomeGymCell {

/// The ViewModel for a Gym Cell on the main view.
@MainActor
class ViewModel: ObservableObject {

// MARK: - Helpers

/// Determine whether at least one fitness center is open at this `Gym`.
func fitnessCenterIsOpen(gym: Gym) -> Bool {
gym.fitnessCenters.allSatisfy {
switch $0.status {
case .closed:
return false
default:
return true
}
}
}

/// Determine the close time of the latest closing fitness center that is currently open at this `Gym`.
func determineCloseTime(gym: Gym) -> Date? {
var possibleCloseTimes: [Date] = []

gym.fitnessCenters.forEach {
switch $0.status {
case .open(let closeTime):
possibleCloseTimes.append(closeTime)
default:
break
}
}

return possibleCloseTimes.sorted(by: {
switch $0.compare($1) {
case .orderedDescending:
return true
default:
return false
}
}).first
}

/// Determine the open time of the earliest opening fitness center of this `Gym`.
func determineOpenTime(gym: Gym) -> Date? {
var possibleOpenTimes: [Date] = []

gym.fitnessCenters.forEach {
switch $0.status {
case .closed(let openTime):
possibleOpenTimes.append(openTime)
default:
break
}
}

return possibleOpenTimes.sorted(by: {
switch $0.compare($1) {
case .orderedAscending:
return true
default:
return false
}
}).first
}

}

}
31 changes: 22 additions & 9 deletions Uplift/Views/Home/GymDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,33 @@ struct GymDetailView: View {
VStack(spacing: 4) {
Spacer()

switch gym.status {
case .closed:
Text("CLOSED")
.font(Constants.Fonts.h3)
.foregroundStyle(Constants.Colors.closed)
case .open:
if viewModel.fitnessCenterIsOpen(gym: gym) {
Text("OPEN")
.font(Constants.Fonts.h3)
.foregroundStyle(Constants.Colors.open)
case .none:
EmptyView()
.padding(12)
} else {
Text("CLOSED")
.font(Constants.Fonts.h3)
.foregroundStyle(Constants.Colors.closed)
.padding(12)
}

viewHoursButton
// TODO: Removed building hours. Determine what should be displayed here.
// switch gym.status {
// case .closed:
// Text("CLOSED")
// .font(Constants.Fonts.h3)
// .foregroundStyle(Constants.Colors.closed)
// case .open:
// Text("OPEN")
// .font(Constants.Fonts.h3)
// .foregroundStyle(Constants.Colors.open)
// case .none:
// EmptyView()
// }
//
// viewHoursButton
Comment on lines +135 to +149
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to delete this for style right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're holding onto this code for now because we had to remove building hours, not sure what we're going to do with it yet.

}
.frame(height: 120)
}
Expand Down
51 changes: 26 additions & 25 deletions Uplift/Views/Home/HomeGymCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct HomeGymCell: View {

// MARK: - Properties

@StateObject private var viewModel = ViewModel()
let gym: Gym

@State private var distance: String = "0.0"
Expand Down Expand Up @@ -63,20 +64,13 @@ struct HomeGymCell: View {
gymNameText
statusText

if gym.fitnessCenters.allSatisfy({
switch $0.status {
case .closed:
return true
default:
return false
}
}) {
if viewModel.fitnessCenterIsOpen(gym: gym) {
capacityText
} else {
// All fitness centers are closed
Text("Fitness Centers Closed")
.font(Constants.Fonts.labelMedium)
.foregroundStyle(Constants.Colors.gray03)
} else {
capacityText
}
}

Expand Down Expand Up @@ -112,21 +106,28 @@ struct HomeGymCell: View {

private var statusText: some View {
HStack(spacing: 8) {
switch gym.status {
case .closed(let openTime):
Text("Closed")
.foregroundStyle(Constants.Colors.closed)

Text("Opens at \(openTime.timeStringNoTrailingZeros)")
.foregroundStyle(Constants.Colors.gray03)
case .open(let closeTime):
Text("Open")
.foregroundStyle(Constants.Colors.open)

Text("Closes at \(closeTime.timeStringNoTrailingZeros)")
.foregroundStyle(Constants.Colors.gray03)
case .none:
EmptyView()
if viewModel.fitnessCenterIsOpen(gym: gym) {
// Currently open, determine close time
if let closeTime = viewModel.determineCloseTime(gym: gym) {
Text("Open")
.foregroundStyle(Constants.Colors.open)

Text("Closes at \(closeTime.timeStringNoTrailingZeros)")
.foregroundStyle(Constants.Colors.gray03)
} else {
EmptyView()
}
} else {
// Currently closed, determine open time
if let openTime = viewModel.determineOpenTime(gym: gym) {
Text("Closed")
.foregroundStyle(Constants.Colors.closed)

Text("Opens at \(openTime.timeStringNoTrailingZeros)")
.foregroundStyle(Constants.Colors.gray03)
} else {
EmptyView()
}
}
}
.font(Constants.Fonts.labelMedium)
Expand Down
4 changes: 2 additions & 2 deletions Uplift/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct HomeView: View {

private var capacitiesView: some View {
VStack(alignment: .leading, spacing: 12) {
Text("GYM CAPACITIES")
Text("FITNESS CENTER CAPACITIES")
.foregroundStyle(Constants.Colors.gray03)
.font(Constants.Fonts.h3)

Expand Down Expand Up @@ -132,7 +132,7 @@ struct HomeView: View {
viewModel.showCapacities ? capacitiesView : nil

HStack {
Text("GYMS")
Text("RECREATION CENTERS")
.foregroundStyle(Constants.Colors.gray03)
.font(Constants.Fonts.h3)

Expand Down