parent
5c534fe22e
commit
a7f8b1bafd
@ -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() |
||||
} |
||||
Loading…
Reference in new issue