parent
d85e22c9ff
commit
f13a71675d
@ -0,0 +1,68 @@ |
||||
// |
||||
// TournamentClubSettingsView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 18/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct TournamentClubSettingsView: View { |
||||
@Environment(Tournament.self) private var tournament: Tournament |
||||
@EnvironmentObject var dataStore: DataStore |
||||
|
||||
var body: some View { |
||||
@Bindable var tournament = tournament |
||||
List { |
||||
let event = tournament.eventObject |
||||
let selectedClub = event?.clubObject |
||||
Section { |
||||
if let selectedClub { |
||||
NavigationLink { |
||||
ClubDetailView(club: selectedClub, displayContext: .edition) |
||||
} label: { |
||||
ClubRowView(club: selectedClub) |
||||
} |
||||
} else { |
||||
NavigationLink { |
||||
ClubsView() { club in |
||||
if let event { |
||||
event.club = club.id |
||||
try? dataStore.events.addOrUpdate(instance: event) |
||||
} else { |
||||
let event = Event(club: club.id) |
||||
tournament.event = event.id |
||||
try? dataStore.events.addOrUpdate(instance: event) |
||||
} |
||||
} |
||||
} label: { |
||||
Text("Choisir un club") |
||||
} |
||||
} |
||||
} header: { |
||||
Text("Lieu du tournoi") |
||||
} footer: { |
||||
if let event, selectedClub != nil { |
||||
HStack { |
||||
Spacer() |
||||
Button("modifier", role: .destructive) { |
||||
event.club = nil |
||||
try? dataStore.events.addOrUpdate(instance: event) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Section { |
||||
TournamentFieldsManagerView(localizedStringKey: "Terrains maximum", count: $tournament.courtCount, max: 100) |
||||
} |
||||
} |
||||
.onDisappear { |
||||
try? dataStore.tournaments.addOrUpdate(instance: tournament) |
||||
} |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
TournamentClubSettingsView() |
||||
} |
||||
@ -0,0 +1,78 @@ |
||||
// |
||||
// TournamentGeneralSettingsView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 18/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct TournamentGeneralSettingsView: View { |
||||
@Environment(Tournament.self) private var tournament: Tournament |
||||
@EnvironmentObject var dataStore: DataStore |
||||
|
||||
@State private var tournamentName: String = "" |
||||
@FocusState private var textFieldIsFocus: Bool |
||||
|
||||
var body: some View { |
||||
@Bindable var tournament = tournament |
||||
Form { |
||||
Section { |
||||
TournamentDatePickerView() |
||||
TournamentDurationManagerView() |
||||
} |
||||
|
||||
Section { |
||||
TournamentLevelPickerView() |
||||
} |
||||
|
||||
Section { |
||||
LabeledContent { |
||||
TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $tournament.entryFee, format: .currency(code: Locale.current.currency?.identifier ?? "EUR")) |
||||
.keyboardType(.decimalPad) |
||||
.multilineTextAlignment(.trailing) |
||||
.frame(maxWidth: .infinity) |
||||
} label: { |
||||
Text("Inscription") |
||||
} |
||||
} |
||||
|
||||
Section { |
||||
LabeledContent { |
||||
TextField("Nom", text: $tournamentName) |
||||
.multilineTextAlignment(.trailing) |
||||
.frame(maxWidth: .infinity) |
||||
.keyboardType(.alphabet) |
||||
.autocorrectionDisabled() |
||||
.onSubmit { |
||||
if tournamentName.trimmed.isEmpty { |
||||
tournament.name = nil |
||||
} else { |
||||
tournament.name = tournamentName |
||||
} |
||||
} |
||||
} label: { |
||||
Text("Nom du tournoi") |
||||
} |
||||
} |
||||
} |
||||
.focused($textFieldIsFocus) |
||||
.scrollDismissesKeyboard(.immediately) |
||||
.navigationTitle("Réglages") |
||||
.toolbarBackground(.visible, for: .navigationBar) |
||||
.toolbar { |
||||
ToolbarItem(placement: .keyboard) { |
||||
Button("Valider") { |
||||
textFieldIsFocus = false |
||||
} |
||||
} |
||||
} |
||||
.onDisappear { |
||||
try? dataStore.tournaments.addOrUpdate(instance: tournament) |
||||
} |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
TournamentGeneralSettingsView() |
||||
} |
||||
@ -0,0 +1,20 @@ |
||||
// |
||||
// TournamentMatchFormatsSettingsView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 18/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct TournamentMatchFormatsSettingsView: View { |
||||
var body: some View { |
||||
List { |
||||
TournamentFormatSelectionView() |
||||
} |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
TournamentMatchFormatsSettingsView() |
||||
} |
||||
Loading…
Reference in new issue