1.03 for iOS and 1.5.0 for Android
This commit is contained in:
@@ -15,6 +15,18 @@ struct SessionDetailView: View {
|
||||
dataManager.session(withId: sessionId)
|
||||
}
|
||||
|
||||
private func startTimer() {
|
||||
// Update every 5 seconds instead of 1 second for better performance
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { _ in
|
||||
currentTime = Date()
|
||||
}
|
||||
}
|
||||
|
||||
private func stopTimer() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
}
|
||||
|
||||
private var gym: Gym? {
|
||||
guard let session = session else { return nil }
|
||||
return dataManager.gym(withId: session.gymId)
|
||||
@@ -35,7 +47,7 @@ struct SessionDetailView: View {
|
||||
calculateSessionStats()
|
||||
}
|
||||
|
||||
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
||||
@State private var timer: Timer?
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
@@ -57,8 +69,11 @@ struct SessionDetailView: View {
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.onReceive(timer) { _ in
|
||||
currentTime = Date()
|
||||
.onAppear {
|
||||
startTimer()
|
||||
}
|
||||
.onDisappear {
|
||||
stopTimer()
|
||||
}
|
||||
.navigationTitle("Session Details")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -153,46 +168,14 @@ struct SessionDetailView: View {
|
||||
let uniqueProblems = Set(attempts.map { $0.problemId })
|
||||
let completedProblems = Set(successfulAttempts.map { $0.problemId })
|
||||
|
||||
let attemptedProblems = uniqueProblems.compactMap { dataManager.problem(withId: $0) }
|
||||
let boulderProblems = attemptedProblems.filter { $0.climbType == .boulder }
|
||||
let ropeProblems = attemptedProblems.filter { $0.climbType == .rope }
|
||||
|
||||
let boulderRange = gradeRange(for: boulderProblems)
|
||||
let ropeRange = gradeRange(for: ropeProblems)
|
||||
|
||||
return SessionStats(
|
||||
totalAttempts: attempts.count,
|
||||
successfulAttempts: successfulAttempts.count,
|
||||
uniqueProblemsAttempted: uniqueProblems.count,
|
||||
uniqueProblemsCompleted: completedProblems.count,
|
||||
boulderRange: boulderRange,
|
||||
ropeRange: ropeRange
|
||||
uniqueProblemsCompleted: completedProblems.count
|
||||
)
|
||||
}
|
||||
|
||||
private func gradeRange(for problems: [Problem]) -> String? {
|
||||
guard !problems.isEmpty else { return nil }
|
||||
let difficulties = problems.map { $0.difficulty }
|
||||
|
||||
// Group by difficulty system first
|
||||
let groupedBySystem = Dictionary(grouping: difficulties) { $0.system }
|
||||
|
||||
// For each system, find the range
|
||||
let ranges = groupedBySystem.compactMap { (system, difficulties) -> String? in
|
||||
let sortedDifficulties = difficulties.sorted()
|
||||
guard let min = sortedDifficulties.first, let max = sortedDifficulties.last else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if min == max {
|
||||
return min.grade
|
||||
} else {
|
||||
return "\(min.grade) - \(max.grade)"
|
||||
}
|
||||
}
|
||||
|
||||
return ranges.joined(separator: ", ")
|
||||
}
|
||||
}
|
||||
|
||||
struct SessionHeaderCard: View {
|
||||
@@ -300,19 +283,6 @@ struct SessionStatsCard: View {
|
||||
StatItem(label: "Successful", value: "\(stats.successfulAttempts)")
|
||||
StatItem(label: "Completed", value: "\(stats.uniqueProblemsCompleted)")
|
||||
}
|
||||
|
||||
// Grade ranges
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
if let boulderRange = stats.boulderRange, let ropeRange = stats.ropeRange {
|
||||
HStack {
|
||||
StatItem(label: "Boulder Range", value: boulderRange)
|
||||
StatItem(label: "Rope Range", value: ropeRange)
|
||||
}
|
||||
} else if let singleRange = stats.boulderRange ?? stats.ropeRange {
|
||||
StatItem(label: "Grade Range", value: singleRange)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
@@ -504,8 +474,6 @@ struct SessionStats {
|
||||
let successfulAttempts: Int
|
||||
let uniqueProblemsAttempted: Int
|
||||
let uniqueProblemsCompleted: Int
|
||||
let boulderRange: String?
|
||||
let ropeRange: String?
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
Reference in New Issue
Block a user