diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 4f07484..15eee50 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -163,11 +163,13 @@ final class GroupStage: ModelObject, Storable { for (index, team) in teams.enumerated() { team.qualified = index < tournament.qualifiedPerGroupStage if team.bracketPosition != nil && team.qualified == false { - tournamentObject()?.resetTeamScores(in: team.bracketPosition) - team.bracketPosition = nil + tournamentObject()?.shouldVerifyBracket = true } } try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: teams) + if let tournamentObject = tournamentObject() { + try DataStore.shared.tournaments.addOrUpdate(instance: tournamentObject) + } } catch { Logger.error(error) } diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 2caee20..b7fa039 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -128,7 +128,7 @@ defer { } func matchWarningMessage() -> String { - [roundTitle(), matchTitle(.short), startDate?.localizedDate(), courtName()].compacted().joined(separator: "\n") + [roundAndMatchTitle(), startDate?.localizedDate(), courtName(), matchFormat.computedLongLabel].compacted().joined(separator: "\n") } func matchTitle(_ displayStyle: DisplayStyle = .wide, inMatches matches: [Match]? = nil) -> String { diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 7d66f8a..a32d6a4 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -2189,7 +2189,8 @@ defer { let newGroup = selected.prefix(seedCount) + selected.filter({ $0.qualified }) let currentGroup = allTeams.filter({ $0.bracketPosition != nil }) let selectedIds = newGroup.map { $0.id } - let groupIds = currentGroup.map { $0.id } + let groupStageTeamsInBracket = selected.filter({ $0.qualified == false && $0.inGroupStage() && $0.inRound() }) + let groupIds = currentGroup.map { $0.id } + groupStageTeamsInBracket.map { $0.id } let shouldBeInIt = Set(selectedIds).subtracting(groupIds) let shouldNotBeInIt = Set(groupIds).subtracting(selectedIds) return (Array(shouldBeInIt), Array(shouldNotBeInIt)) diff --git a/PadelClub/ViewModel/MatchDescriptor.swift b/PadelClub/ViewModel/MatchDescriptor.swift index 8072cb3..bbb444a 100644 --- a/PadelClub/ViewModel/MatchDescriptor.swift +++ b/PadelClub/ViewModel/MatchDescriptor.swift @@ -1,11 +1,12 @@ // -// MatchDescriptor.swift +// swift // PadelClub // // Created by Razmig Sarkissian on 02/04/2024. // import Foundation +import SwiftUI class MatchDescriptor: ObservableObject { @Published var matchFormat: MatchFormat @@ -16,6 +17,77 @@ class MatchDescriptor: ObservableObject { var teamLabelTwo: String = "" var startDate: Date = Date() var match: Match? + let colorTeamOne: Color = .teal + let colorTeamTwo: Color = .indigo + + var teamOneSetupIsActive: Bool { + if hasEnded && showSetInputView == false && showTieBreakInputView == false { + return false + } + + guard let setDescriptor = setDescriptors.last else { + return false + } + if setDescriptor.valueTeamOne == nil { + return true + } else if setDescriptor.valueTeamTwo == nil { + return false + } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { + return true + } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { + return false + } + + return false + } + + var teamTwoSetupIsActive: Bool { + if hasEnded && showSetInputView == false && showTieBreakInputView == false { + return false + } + guard let setDescriptor = setDescriptors.last else { + return false + } + + if setDescriptor.valueTeamOne == nil { + return false + } else if setDescriptor.valueTeamTwo == nil { + return true + } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { + return false + } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { + return true + } + + return true + } + + func getColor() -> Color { + guard let setDescriptor = setDescriptors.last else { + return .master + } + + if setDescriptor.valueTeamOne == nil { + return colorTeamOne + } else if setDescriptor.valueTeamTwo == nil { + return colorTeamTwo + } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { + return colorTeamOne + } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { + return colorTeamTwo + } + + return colorTeamTwo + } + + + var showSetInputView: Bool { + return setDescriptors.anySatisfy({ $0.showSetInputView }) + } + + var showTieBreakInputView: Bool { + return setDescriptors.anySatisfy({ $0.showTieBreakInputView }) + } init(match: Match? = nil) { self.match = match diff --git a/PadelClub/ViewModel/SetDescriptor.swift b/PadelClub/ViewModel/SetDescriptor.swift index d5b8e5f..fef0db5 100644 --- a/PadelClub/ViewModel/SetDescriptor.swift +++ b/PadelClub/ViewModel/SetDescriptor.swift @@ -14,7 +14,9 @@ struct SetDescriptor: Identifiable, Equatable { var tieBreakValueTeamOne: Int? var tieBreakValueTeamTwo: Int? var setFormat: SetFormat - + var showSetInputView: Bool = true + var showTieBreakInputView: Bool = false + var hasEnded: Bool { if let valueTeamTwo, let valueTeamOne { return setFormat.hasEnded(teamOne: valueTeamOne, teamTwo: valueTeamTwo) diff --git a/PadelClub/Views/Navigation/Toolbox/MatchFormatStorageView.swift b/PadelClub/Views/Navigation/Toolbox/MatchFormatStorageView.swift index 0e03920..b389892 100644 --- a/PadelClub/Views/Navigation/Toolbox/MatchFormatStorageView.swift +++ b/PadelClub/Views/Navigation/Toolbox/MatchFormatStorageView.swift @@ -24,8 +24,9 @@ struct MatchFormatStorageView: View { LabeledContent { StepperView(title: "minutes", count: $estimatedDuration, step: 5) } label: { - Text("Durée \(matchFormat.format)") - Text(matchFormat.computedShortLabelWithoutPrefix) + Text("Durée \(matchFormat.format)" + matchFormat.suffix) + Text(matchFormat.longLabel) + Text(matchFormat.formattedEstimatedBreakDuration() + " de pause").foregroundStyle(.secondary).font(.subheadline) } } footer: { if estimatedDuration != matchFormat.defaultEstimatedDuration { diff --git a/PadelClub/Views/Score/EditScoreView.swift b/PadelClub/Views/Score/EditScoreView.swift index 3110e4f..639d2bf 100644 --- a/PadelClub/Views/Score/EditScoreView.swift +++ b/PadelClub/Views/Score/EditScoreView.swift @@ -8,37 +8,6 @@ import SwiftUI import LeStorage -struct ArrowView: View { - var direction: ArrowDirection // Enum for left or right direction - var isActive: Bool // Whether the arrow is visible - var color: Color - @State private var isAnimating = false - - enum ArrowDirection { - case left, right - } - - var body: some View { - Image(systemName: direction == .left ? "arrow.left" : "arrow.right") - .font(.title) - .foregroundColor(isActive ? color : .clear) // Arrow visible only when active - .opacity(isAnimating ? 1.0 : 0.4) // Animate opacity between 1.0 and 0.4 - .offset(x: isAnimating ? (direction == .left ? -5 : 5) : 0) // Slight left/right movement - .animation( - Animation.easeInOut(duration: 0.7).repeatForever(autoreverses: true), - value: isAnimating - ) - .onAppear { - isAnimating = true - } - .onDisappear { - isAnimating = false - } - .padding() - } -} - - struct EditScoreView: View { @EnvironmentObject var dataStore: DataStore @@ -46,11 +15,6 @@ struct EditScoreView: View { @StateObject var matchDescriptor: MatchDescriptor @Binding var confirmScoreEdition: Bool @Environment(\.dismiss) private var dismiss - @State private var showSetInputView: Bool = true - @State private var showTieBreakInputView: Bool = false - - let colorTeamOne: Color = .teal - let colorTeamTwo: Color = .indigo init(match: Match, confirmScoreEdition: Binding) { let matchDescriptor = MatchDescriptor(match: match) @@ -90,7 +54,7 @@ struct EditScoreView: View { .bold() } } - .listRowView(isActive: teamOneSetupIsActive, color: colorTeamOne, hideColorVariation: false) + .listRowView(isActive: matchDescriptor.teamOneSetupIsActive, color: matchDescriptor.colorTeamOne, hideColorVariation: false) HStack { Spacer() VStack(alignment: .trailing) { @@ -101,7 +65,7 @@ struct EditScoreView: View { } } } - .listRowView(isActive: teamTwoSetupIsActive, color: colorTeamTwo, hideColorVariation: false, alignment: .trailing) + .listRowView(isActive: matchDescriptor.teamTwoSetupIsActive, color: matchDescriptor.colorTeamTwo, hideColorVariation: false, alignment: .trailing) } header: { if let roundTitle = matchDescriptor.match?.roundAndMatchTitle() { Text(roundTitle) @@ -133,7 +97,7 @@ struct EditScoreView: View { } } ForEach($matchDescriptor.setDescriptors) { $setDescriptor in - SetInputView(setDescriptor: $setDescriptor, showSetInputView: $showSetInputView, showTieBreakInputView: $showTieBreakInputView) + SetInputView(setDescriptor: $setDescriptor) .onChange(of: setDescriptor.hasEnded) { if setDescriptor.hasEnded { if matchDescriptor.hasEnded == false { @@ -144,7 +108,7 @@ struct EditScoreView: View { matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index]) } } - .tint(getColor()) + .tint(matchDescriptor.getColor()) } if matchDescriptor.hasEnded { @@ -191,66 +155,4 @@ struct EditScoreView: View { } } } - - - var teamOneSetupIsActive: Bool { - if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false { - return false - } - - guard let setDescriptor = matchDescriptor.setDescriptors.last else { - return false - } - if setDescriptor.valueTeamOne == nil { - return true - } else if setDescriptor.valueTeamTwo == nil { - return false - } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { - return true - } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { - return false - } - - return false - } - - var teamTwoSetupIsActive: Bool { - if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false { - return false - } - guard let setDescriptor = matchDescriptor.setDescriptors.last else { - return false - } - - if setDescriptor.valueTeamOne == nil { - return false - } else if setDescriptor.valueTeamTwo == nil { - return true - } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { - return false - } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { - return true - } - - return true - } - - func getColor() -> Color { - guard let setDescriptor = matchDescriptor.setDescriptors.last else { - return .master - } - - if setDescriptor.valueTeamOne == nil { - return colorTeamOne - } else if setDescriptor.valueTeamTwo == nil { - return colorTeamTwo - } else if setDescriptor.tieBreakValueTeamOne == nil, setDescriptor.shouldTieBreak { - return colorTeamOne - } else if setDescriptor.tieBreakValueTeamTwo == nil, setDescriptor.shouldTieBreak { - return colorTeamTwo - } - - return colorTeamTwo - } - } diff --git a/PadelClub/Views/Score/SetInputView.swift b/PadelClub/Views/Score/SetInputView.swift index 4fbbb64..231e168 100644 --- a/PadelClub/Views/Score/SetInputView.swift +++ b/PadelClub/Views/Score/SetInputView.swift @@ -9,8 +9,8 @@ import SwiftUI struct SetInputView: View { @Binding var setDescriptor: SetDescriptor - @Binding var showSetInputView: Bool - @Binding var showTieBreakInputView: Bool + @State private var showSetInputView: Bool = true + @State private var showTieBreakInputView: Bool = false var setFormat: SetFormat { setDescriptor.setFormat } @@ -137,6 +137,12 @@ struct SetInputView: View { } } } + .onChange(of: showSetInputView) { + setDescriptor.showSetInputView = showSetInputView + } + .onChange(of: showTieBreakInputView) { + setDescriptor.showTieBreakInputView = showTieBreakInputView + } .onChange(of: setDescriptor.valueTeamOne) { if let newValue = setDescriptor.valueTeamOne { if newValue == setFormat.scoreToWin - 1 && setFormat.tieBreak == 8 {