fix match dispatcher

multistore
Razmig Sarkissian 2 years ago
parent 3a2d242e13
commit 69dcc5a16d
  1. 41
      PadelClub/ViewModel/MatchScheduler.swift
  2. 2
      PadelClub/Views/Calling/CallView.swift
  3. 4
      PadelClub/Views/Planning/Components/DateUpdateManagerView.swift
  4. 3
      PadelClub/Views/Planning/GroupStageScheduleEditorView.swift
  5. 4
      PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift
  6. 2
      PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift
  7. 1
      PadelClub/Views/Planning/RoundScheduleEditorView.swift
  8. 1
      PadelClub/Views/Planning/SchedulerView.swift

@ -494,22 +494,41 @@ class MatchScheduler {
} }
}) })
if let roundId { // if let roundId {
if let round : Round = Store.main.findById(roundId) { // if let round : Round = Store.main.findById(roundId) {
let matches = round._matches() // let matches = round._matches().filter({ $0.disabled == false }).sorted(by: \.index)
round.resetFromRoundAllMatchesStartDate() // round.resetFromRoundAllMatchesStartDate()
flattenedMatches = matches + flattenedMatches // flattenedMatches = matches + flattenedMatches
// }
//
// } else if let matchId {
// if let match : Match = Store.main.findById(matchId) {
// if let round = match.roundObject {
// round.resetFromRoundAllMatchesStartDate(from: match)
// }
// flattenedMatches = [match] + flattenedMatches
// }
// }
if let roundId, let matchId {
//todo
if let index = flattenedMatches.firstIndex(where: { $0.round == roundId && $0.id == matchId }) {
flattenedMatches[index...].forEach {
$0.startDate = nil
$0.removeCourt()
}
} }
} else if let roundId {
} else if let matchId { //todo
if let match : Match = Store.main.findById(matchId) { if let index = flattenedMatches.firstIndex(where: { $0.round == roundId }) {
if let round = match.roundObject { flattenedMatches[index...].forEach {
round.resetFromRoundAllMatchesStartDate(from: match) $0.startDate = nil
$0.removeCourt()
} }
flattenedMatches = [match] + flattenedMatches
} }
} }
let usedCourts = getAvailableCourts(from: allMatches.filter({ $0.startDate?.isEarlierThan(startDate) == true && $0.startDate?.dayInt == startDate.dayInt })) let usedCourts = getAvailableCourts(from: allMatches.filter({ $0.startDate?.isEarlierThan(startDate) == true && $0.startDate?.dayInt == startDate.dayInt }))
let initialCourts = usedCourts.filter { (court, availableDate) in let initialCourts = usedCourts.filter { (court, availableDate) in
availableDate <= startDate availableDate <= startDate

@ -84,7 +84,7 @@ struct CallView: View {
var body: some View { var body: some View {
let callWord = teams.allSatisfy({ $0.called() }) ? "Reconvoquer" : "Convoquer" let callWord = teams.allSatisfy({ $0.called() }) ? "Reconvoquer" : "Convoquer"
HStack(spacing: 0.0) { HStack {
if teams.count == 1 { if teams.count == 1 {
if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame { if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame {
Text("Reconvoquer " + callDate.localizedDate() + " par") Text("Reconvoquer " + callDate.localizedDate() + " par")

@ -47,12 +47,12 @@ struct DateUpdateManagerView: View {
Spacer() Spacer()
if dateUpdated { if dateUpdated {
FooterButtonView("valider la modification") { FooterButtonView("valider l'horaire") {
validateAction() validateAction()
dateUpdated = false dateUpdated = false
} }
} else if currentDate != nil { } else if currentDate != nil {
FooterButtonView("horaire automatique") { FooterButtonView("retirer l'horaire") {
currentDate = nil currentDate = nil
} }
} }

@ -12,6 +12,7 @@ struct GroupStageScheduleEditorView: View {
@Bindable var groupStage: GroupStage @Bindable var groupStage: GroupStage
var tournament: Tournament var tournament: Tournament
@State private var startDate: Date @State private var startDate: Date
@State private var uuid: UUID = UUID()
init(groupStage: GroupStage, tournament: Tournament) { init(groupStage: GroupStage, tournament: Tournament) {
self.groupStage = groupStage self.groupStage = groupStage
@ -31,8 +32,10 @@ struct GroupStageScheduleEditorView: View {
DateUpdateManagerView(startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { DateUpdateManagerView(startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
groupStage.startDate = startDate groupStage.startDate = startDate
_save() _save()
uuid = UUID()
} }
} }
.id(uuid)
} }

@ -43,11 +43,13 @@ struct LoserRoundScheduleEditorView: View {
ForEach(enabledLoserRounds.indices, id: \.self) { index in ForEach(enabledLoserRounds.indices, id: \.self) { index in
let loserRound = enabledLoserRounds[index] let loserRound = enabledLoserRounds[index]
LoserRoundStepScheduleEditorView(stepIndex: index, round: loserRound, upperRound: upperRound) LoserRoundStepScheduleEditorView(stepIndex: index, round: loserRound, upperRound: upperRound)
.id(UUID())
} }
} }
.onChange(of: matchFormat) { .onChange(of: matchFormat) {
loserRounds.forEach { round in loserRounds.forEach { round in
round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) round.updateMatchFormatAndAllMatches(matchFormat)
//round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true)
} }
_save() _save()
} }

@ -61,7 +61,7 @@ struct LoserRoundStepScheduleEditorView: View {
} }
.headerProminence(.increased) .headerProminence(.increased)
.onChange(of: matchFormat) { .onChange(of: matchFormat) {
round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) round.updateMatchFormatAndAllMatches(matchFormat)
_save() _save()
} }
.onChange(of: round.startDate) { .onChange(of: round.startDate) {

@ -35,6 +35,7 @@ struct RoundScheduleEditorView: View {
ForEach(round.playedMatches()) { match in ForEach(round.playedMatches()) { match in
MatchScheduleEditorView(match: match) MatchScheduleEditorView(match: match)
.id(UUID())
} }
} }
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)

@ -48,6 +48,7 @@ struct SchedulerView: View {
} }
ForEach(tournament.groupStages()) { ForEach(tournament.groupStages()) {
GroupStageScheduleEditorView(groupStage: $0, tournament: tournament) GroupStageScheduleEditorView(groupStage: $0, tournament: tournament)
.id(UUID())
} }
case .scheduleBracket: case .scheduleBracket:
ForEach(tournament.rounds()) { round in ForEach(tournament.rounds()) { round in

Loading…
Cancel
Save