refactoring

sync3
Laurent 6 months ago
parent 6cefe91b37
commit c7575d1d67
  1. 2
      PadelClub/Views/Calling/GroupStageCallingView.swift
  2. 14
      PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift
  3. 2
      PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift
  4. 2
      PadelClub/Views/GroupStage/GroupStageView.swift
  5. 6
      PadelClub/Views/GroupStage/GroupStagesSettingsView.swift

@ -114,7 +114,7 @@ struct GroupStageCallingView: View {
} }
} }
.overlay { .overlay {
if groupStage.startDate == nil && groupStage._matches().filter({ $0.startDate != nil }).isEmpty { if groupStage.startDate == nil && groupStage.matches().filter({ $0.startDate != nil }).isEmpty {
ContentUnavailableView { ContentUnavailableView {
Label("Aucun horaire défini", systemImage: "clock.badge.questionmark") Label("Aucun horaire défini", systemImage: "clock.badge.questionmark")
} description: { } description: {

@ -27,7 +27,7 @@ struct GroupStageSettingsView: View {
_groupStage = Bindable(groupStage) _groupStage = Bindable(groupStage)
_groupStageName = .init(wrappedValue: groupStage.name ?? "") _groupStageName = .init(wrappedValue: groupStage.name ?? "")
_size = .init(wrappedValue: groupStage.size) _size = .init(wrappedValue: groupStage.size)
_courtIndex = .init(wrappedValue: groupStage._matches().first?.courtIndex ?? 0) _courtIndex = .init(wrappedValue: groupStage.matches().first?.courtIndex ?? 0)
} }
var tournamentStore: TournamentStore? { var tournamentStore: TournamentStore? {
@ -66,12 +66,12 @@ struct GroupStageSettingsView: View {
Section { Section {
CourtPicker(title: "Terrain dédié", selection: $courtIndex, maxCourt: tournament.courtCount) CourtPicker(title: "Terrain dédié", selection: $courtIndex, maxCourt: tournament.courtCount)
RowButtonView("Confirmer", role: .destructive) { RowButtonView("Confirmer", role: .destructive) {
groupStage._matches().forEach { match in groupStage.matches().forEach { match in
match.setCourt(courtIndex) match.setCourt(courtIndex)
} }
do { do {
try tournamentStore?.matches.addOrUpdate(contentOfs: groupStage._matches()) try tournamentStore?.matches.addOrUpdate(contentOfs: groupStage.matches())
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
@ -91,7 +91,7 @@ struct GroupStageSettingsView: View {
teams.forEach { team in teams.forEach { team in
team.groupStagePosition = nil team.groupStagePosition = nil
team.groupStage = nil team.groupStage = nil
groupStage._matches().forEach({ $0.updateTeamScores() }) groupStage.matches().forEach({ $0.updateTeamScores() })
} }
do { do {
try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams)
@ -111,13 +111,13 @@ struct GroupStageSettingsView: View {
Section { Section {
RowButtonView("Retirer tous les horaires", role: .destructive) { RowButtonView("Retirer tous les horaires", role: .destructive) {
groupStage._matches().forEach { match in groupStage.matches().forEach { match in
match.startDate = nil match.startDate = nil
match.endDate = nil match.endDate = nil
} }
do { do {
try tournamentStore?.matches.addOrUpdate(contentOfs: groupStage._matches()) try tournamentStore?.matches.addOrUpdate(contentOfs: groupStage.matches())
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
@ -130,7 +130,7 @@ struct GroupStageSettingsView: View {
teams.forEach { team in teams.forEach { team in
team.groupStagePosition = nil team.groupStagePosition = nil
team.groupStage = nil team.groupStage = nil
groupStage._matches().forEach({ $0.updateTeamScores() }) groupStage.matches().forEach({ $0.updateTeamScores() })
} }
do { do {
try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams)

@ -103,7 +103,7 @@ struct GroupStageTeamView: View {
team.groupStagePosition = nil team.groupStagePosition = nil
team.groupStage = nil team.groupStage = nil
_save() _save()
groupStage._matches().forEach({ $0.updateTeamScores() }) groupStage.matches().forEach({ $0.updateTeamScores() })
} }
} }
} }

@ -245,7 +245,7 @@ struct GroupStageView: View {
print(team.pasteData()) print(team.pasteData())
team.groupStage = groupStage.id team.groupStage = groupStage.id
team.groupStagePosition = index team.groupStagePosition = index
groupStage._matches().forEach({ $0.updateTeamScores() }) groupStage.matches().forEach({ $0.updateTeamScores() })
do { do {
try tournamentStore?.teamRegistrations.addOrUpdate(instance: team) try tournamentStore?.teamRegistrations.addOrUpdate(instance: team)
} catch { } catch {

@ -144,8 +144,8 @@ struct GroupStagesSettingsView: View {
Section { Section {
RowButtonView("Retirer tous les horaires", role: .destructive) { RowButtonView("Retirer tous les horaires", role: .destructive) {
let matches = tournament.groupStages().flatMap({ $0._matches() }) let matches = tournament.groupStages().flatMap({ $0.matches() })
tournament.groupStages().flatMap({ $0._matches() }).forEach { match in tournament.groupStages().flatMap({ $0.matches() }).forEach { match in
match.startDate = nil match.startDate = nil
match.endDate = nil match.endDate = nil
} }
@ -239,7 +239,7 @@ struct GroupStagesSettingsView: View {
teams.forEach { team in teams.forEach { team in
team.groupStagePosition = nil team.groupStagePosition = nil
team.groupStage = nil team.groupStage = nil
groupStage._matches().forEach({ $0.updateTeamScores() }) groupStage.matches().forEach({ $0.updateTeamScores() })
} }
do { do {
try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) try tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams)

Loading…
Cancel
Save