commit
8a2197bbfd
@ -0,0 +1,22 @@ |
||||
// |
||||
// BroadcastView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 01/05/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct BroadcastView: View { |
||||
var body: some View { |
||||
List { |
||||
} |
||||
.navigationTitle("Diffusion") |
||||
.navigationBarTitleDisplayMode(.inline) |
||||
.toolbarBackground(.visible, for: .navigationBar) |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
BroadcastView() |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
// |
||||
// TournamentStatusView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 01/05/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
import LeStorage |
||||
|
||||
struct TournamentStatusView: View { |
||||
@Environment(Tournament.self) private var tournament: Tournament |
||||
@EnvironmentObject var dataStore: DataStore |
||||
|
||||
var body: some View { |
||||
@Bindable var tournament = tournament |
||||
Form { |
||||
Section { |
||||
RowButtonView("Supprimer le tournoi", role: .destructive) { |
||||
tournament.isDeleted.toggle() |
||||
} |
||||
} footer: { |
||||
Text("todo: expliquer ce que ca fait") |
||||
} |
||||
Section { |
||||
if tournament.hasEnded() == false { |
||||
if tournament.isCanceled == false { |
||||
RowButtonView("Annuler le tournoi", role: .destructive) { |
||||
tournament.isCanceled.toggle() |
||||
} |
||||
} else { |
||||
RowButtonView("Reprendre le tournoi", role: .destructive) { |
||||
tournament.isCanceled.toggle() |
||||
} |
||||
} |
||||
} |
||||
} footer: { |
||||
Text("todo: expliquer ce que ca fait") |
||||
} |
||||
|
||||
Section { |
||||
Toggle(isOn: $tournament.isPrivate) { |
||||
Text("Tournoi privée") |
||||
} |
||||
} footer: { |
||||
Text("Le tournoi sera masqué sur le site padelclub.app") |
||||
} |
||||
} |
||||
.toolbarBackground(.visible, for: .navigationBar) |
||||
.onChange(of: [tournament.isDeleted, tournament.isCanceled, tournament.isPrivate]) { |
||||
_save() |
||||
} |
||||
} |
||||
|
||||
private func _save() { |
||||
do { |
||||
try dataStore.tournaments.addOrUpdate(instance: tournament) |
||||
} catch { |
||||
Logger.error(error) |
||||
} |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
TournamentStatusView() |
||||
} |
||||
@ -0,0 +1,106 @@ |
||||
// |
||||
// TournamentRankView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 30/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
import LeStorage |
||||
|
||||
struct TournamentRankView: View { |
||||
@Environment(Tournament.self) var tournament: Tournament |
||||
@EnvironmentObject var dataStore: DataStore |
||||
|
||||
@State private var rankings: [Int: [TeamRegistration]] = [:] |
||||
|
||||
var body: some View { |
||||
List { |
||||
let keys = rankings.keys.sorted() |
||||
ForEach(keys, id: \.self) { key in |
||||
if let rankedTeams = rankings[key] { |
||||
ForEach(rankedTeams) { team in |
||||
HStack { |
||||
VStack(alignment: .trailing) { |
||||
VStack(alignment: .trailing, spacing: -8.0) { |
||||
ZStack(alignment: .trailing) { |
||||
Text(tournament.teamCount.formatted()).hidden() |
||||
Text(key.formatted()) |
||||
} |
||||
.monospacedDigit() |
||||
.font(.largeTitle) |
||||
.fontWeight(.bold) |
||||
Text(key.ordinalFormattedSuffix()).font(.caption) |
||||
} |
||||
if let index = tournament.indexOf(team: team) { |
||||
let rankingDifference = index - (key - 1) |
||||
if rankingDifference > 0 { |
||||
HStack(spacing: 0.0) { |
||||
Text(rankingDifference.formatted(.number.sign(strategy: .always()))) |
||||
.monospacedDigit() |
||||
Image(systemName: "arrowtriangle.up.fill") |
||||
.imageScale(.small) |
||||
} |
||||
.foregroundColor(.green) |
||||
} else if rankingDifference < 0 { |
||||
HStack(spacing: 0.0) { |
||||
Text(rankingDifference.formatted(.number.sign(strategy: .always()))) |
||||
.monospacedDigit() |
||||
Image(systemName: "arrowtriangle.down.fill") |
||||
.imageScale(.small) |
||||
} |
||||
.foregroundColor(.red) |
||||
} else { |
||||
Text("--") |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
Divider() |
||||
|
||||
VStack(alignment: .leading) { |
||||
ForEach(team.players()) { player in |
||||
VStack(alignment: .leading, spacing: -4.0) { |
||||
Text(player.playerLabel()).bold() |
||||
HStack(alignment: .firstTextBaseline, spacing: 0.0) { |
||||
Text(player.rankLabel()) |
||||
if let rank = player.getRank() { |
||||
Text(rank.ordinalFormattedSuffix()) |
||||
.font(.caption) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Spacer() |
||||
VStack(alignment: .trailing) { |
||||
HStack(alignment: .lastTextBaseline, spacing: 0.0) { |
||||
Text(tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount).formatted(.number.sign(strategy: .always()))) |
||||
Text("pts").font(.caption) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.listStyle(.grouped) |
||||
.onAppear { |
||||
let finalRanks = tournament.finalRanking() |
||||
finalRanks.keys.sorted().forEach { rank in |
||||
if let rankedTeamIds = finalRanks[rank] { |
||||
rankings[rank] = rankedTeamIds.compactMap { Store.main.findById($0) } |
||||
} |
||||
} |
||||
} |
||||
.navigationTitle("Classement") |
||||
.navigationBarTitleDisplayMode(.inline) |
||||
.toolbarBackground(.visible, for: .navigationBar) |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
TournamentRankView() |
||||
} |
||||
Loading…
Reference in new issue