parent
4b4f2c74be
commit
4abd2c5d48
@ -0,0 +1,54 @@ |
|||||||
|
// |
||||||
|
// EventSettingsView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 17/05/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
struct EventSettingsView: View { |
||||||
|
@EnvironmentObject var dataStore: DataStore |
||||||
|
@Bindable var event: Event |
||||||
|
@State private var eventName: String = "" |
||||||
|
|
||||||
|
init(event: Event) { |
||||||
|
self.event = event |
||||||
|
_eventName = State(wrappedValue: event.name ?? "") |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
Form { |
||||||
|
Section { |
||||||
|
TextField("Nom de l'événement", text: $eventName) |
||||||
|
.autocorrectionDisabled() |
||||||
|
.keyboardType(.alphabet) |
||||||
|
.onSubmit { |
||||||
|
if eventName.trimmed.isEmpty == false { |
||||||
|
event.name = eventName.trimmed |
||||||
|
} else { |
||||||
|
event.name = nil |
||||||
|
} |
||||||
|
_save() |
||||||
|
} |
||||||
|
} footer: { |
||||||
|
if eventName.isEmpty == false { |
||||||
|
FooterButtonView("effacer le nom") { |
||||||
|
eventName = "" |
||||||
|
event.name = nil |
||||||
|
_save() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private func _save() { |
||||||
|
do { |
||||||
|
try dataStore.events.addOrUpdate(instance: event) |
||||||
|
} catch { |
||||||
|
Logger.error(error) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,91 @@ |
|||||||
|
// |
||||||
|
// EventTournamentsView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 17/05/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
struct EventTournamentsView: View { |
||||||
|
@EnvironmentObject var dataStore: DataStore |
||||||
|
@Environment(NavigationViewModel.self) private var navigation |
||||||
|
let event: Event |
||||||
|
@State private var newTournament: Tournament? |
||||||
|
|
||||||
|
var presentTournamentCreationView: Binding<Bool> { Binding( |
||||||
|
get: { newTournament != nil }, |
||||||
|
set: { isPresented in |
||||||
|
if isPresented == false { |
||||||
|
newTournament = nil |
||||||
|
} |
||||||
|
} |
||||||
|
)} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
let tournaments = event.tournaments |
||||||
|
List { |
||||||
|
ForEach(tournaments) { tournament in |
||||||
|
TournamentCellView(tournament: tournament) |
||||||
|
.contextMenu { |
||||||
|
Button { |
||||||
|
navigation.openTournamentInOrganizer(tournament) |
||||||
|
} label: { |
||||||
|
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.toolbar { |
||||||
|
ToolbarItem(placement: .topBarTrailing) { |
||||||
|
BarButtonView("Ajouter une épreuve", icon: "plus.circle.fill") { |
||||||
|
let tournament = Tournament.newEmptyInstance() |
||||||
|
newTournament = tournament |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.navigationTitle(event.eventTitle()) |
||||||
|
.sheet(isPresented: presentTournamentCreationView) { |
||||||
|
if let newTournament { |
||||||
|
NavigationStack { |
||||||
|
List { |
||||||
|
Section { |
||||||
|
TournamentConfigurationView(tournament: newTournament) |
||||||
|
} |
||||||
|
Section { |
||||||
|
RowButtonView("Ajouter l'épreuve") { |
||||||
|
newTournament.event = event.id |
||||||
|
newTournament.courtCount = event.eventCourtCount() |
||||||
|
newTournament.startDate = event.eventStartDate() |
||||||
|
newTournament.dayDuration = event.eventDayDuration() |
||||||
|
newTournament.setupFederalSettings() |
||||||
|
|
||||||
|
do { |
||||||
|
try dataStore.tournaments.addOrUpdate(instance: newTournament) |
||||||
|
} catch { |
||||||
|
Logger.error(error) |
||||||
|
} |
||||||
|
|
||||||
|
self.newTournament = nil |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.navigationTitle("Nouvelle épreuve") |
||||||
|
.toolbar { |
||||||
|
ToolbarItem(placement: .cancellationAction) { |
||||||
|
Button("Annuler", role: .cancel) { |
||||||
|
self.newTournament = nil |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
// |
||||||
|
// EventView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 17/05/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
enum EventDestination: Identifiable, Selectable { |
||||||
|
case tournaments(Event) |
||||||
|
case cashier |
||||||
|
|
||||||
|
var id: String { |
||||||
|
return String(describing: self) |
||||||
|
} |
||||||
|
|
||||||
|
func selectionLabel() -> String { |
||||||
|
switch self { |
||||||
|
case .tournaments: |
||||||
|
return "Épreuves" |
||||||
|
case .cashier: |
||||||
|
return "Finance" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func badgeValue() -> Int? { |
||||||
|
switch self { |
||||||
|
case .tournaments(let event): |
||||||
|
return event.tournaments.count |
||||||
|
case .cashier: |
||||||
|
return nil |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func badgeValueColor() -> Color? { |
||||||
|
return .logoBackground |
||||||
|
} |
||||||
|
|
||||||
|
func badgeImage() -> Badge? { |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
struct EventView: View { |
||||||
|
let event: Event |
||||||
|
@State private var selectedDestination: EventDestination? |
||||||
|
|
||||||
|
func allDestinations() -> [EventDestination] { |
||||||
|
[.tournaments(event), .cashier] |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
VStack(spacing: 0) { |
||||||
|
GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: allDestinations(), nilDestinationIsValid: true) |
||||||
|
switch selectedDestination { |
||||||
|
case .none: |
||||||
|
EventSettingsView(event: event) |
||||||
|
.navigationTitle("Réglages") |
||||||
|
case .some(let selectedEventDestination): |
||||||
|
switch selectedEventDestination { |
||||||
|
case .tournaments(let event): |
||||||
|
EventTournamentsView(event: event) |
||||||
|
case .cashier: |
||||||
|
CashierDetailView(tournaments: event.tournaments) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.navigationTitle(event.eventTitle()) |
||||||
|
} |
||||||
|
} |
||||||
@ -1,18 +0,0 @@ |
|||||||
// |
|
||||||
// PlayerListView.swift |
|
||||||
// PadelClub |
|
||||||
// |
|
||||||
// Created by Razmig Sarkissian on 17/04/2024. |
|
||||||
// |
|
||||||
|
|
||||||
import SwiftUI |
|
||||||
|
|
||||||
struct PlayerListView: View { |
|
||||||
var body: some View { |
|
||||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#Preview { |
|
||||||
PlayerListView() |
|
||||||
} |
|
||||||
Loading…
Reference in new issue