add tournament name in subtitle in a lot of subviews add the ability to transfer tournaments into an event fix broadcast view page to better display some sharing optionssync3
parent
86c1fa26cc
commit
8602881562
@ -0,0 +1,22 @@ |
||||
// |
||||
// View+Extensions.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 29/09/2025. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
extension View { |
||||
/// Runs a transform only on iOS 26+, otherwise returns self |
||||
@ViewBuilder |
||||
func ifAvailableiOS26<Content: View>( |
||||
@ViewBuilder transform: (Self) -> Content |
||||
) -> some View { |
||||
if #available(iOS 26.0, *) { |
||||
transform(self) |
||||
} else { |
||||
self |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,91 @@ |
||||
// |
||||
// TournamentPickerView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 29/09/2025. |
||||
// |
||||
|
||||
import SwiftUI |
||||
import LeStorage |
||||
import PadelClubData |
||||
import TipKit |
||||
|
||||
struct TournamentPickerView: View { |
||||
@EnvironmentObject var dataStore: DataStore |
||||
@Environment(\.dismiss) private var dismiss |
||||
let mergeTournamentTip = MergeTournamentTip() |
||||
let event: Event |
||||
@State private var selectedTournamentIds: Set<String> = Set() |
||||
@State private var shouldEraseEmptyEvents: Bool = false |
||||
|
||||
var tournaments: [Tournament] { |
||||
dataStore.tournaments.filter({ $0.isDeleted == false && $0.event?.id != event.id }).sorted(by: \.startDate, order: .descending) |
||||
} |
||||
|
||||
var body: some View { |
||||
List(selection: $selectedTournamentIds) { |
||||
Section { |
||||
TipView(mergeTournamentTip) |
||||
.tipStyle(tint: .green) |
||||
} |
||||
|
||||
Section { |
||||
Toggle(isOn: $shouldEraseEmptyEvents) { |
||||
Text("Effacer les événements vides") |
||||
Text("Les événements qui n'ont plus de tournois seront effacés automatiquement.") |
||||
} |
||||
} |
||||
|
||||
ForEach(tournaments) { tournament in |
||||
TournamentCellView(tournament: tournament).tag(tournament.id) |
||||
} |
||||
} |
||||
.environment(\.editMode, Binding.constant(EditMode.active)) |
||||
.toolbar { |
||||
ToolbarItem(placement: .topBarLeading) { |
||||
Button("Annuler") { |
||||
dismiss() |
||||
} |
||||
} |
||||
ToolbarItem(placement: .topBarTrailing) { |
||||
ButtonValidateView { |
||||
_transferTournaments() |
||||
dismiss() |
||||
} |
||||
.disabled(selectedTournamentIds.isEmpty) |
||||
} |
||||
} |
||||
.navigationTitle("Transfert de tournois") |
||||
} |
||||
|
||||
private func _transferTournaments() { |
||||
let tournaments = tournaments |
||||
var eventIdsToCheck = Set<String>() |
||||
var tournamentsToSave = [Tournament]() |
||||
selectedTournamentIds.forEach { id in |
||||
if let tournament = tournaments.first(where: { $0.id == id }) { |
||||
if let eventId = tournament.event{ |
||||
eventIdsToCheck.insert(eventId) |
||||
} |
||||
tournament.event = event.id |
||||
tournamentsToSave.append(tournament) |
||||
} |
||||
} |
||||
|
||||
dataStore.tournaments.addOrUpdate(contentOfs: tournamentsToSave) |
||||
|
||||
if shouldEraseEmptyEvents { |
||||
|
||||
var eventsToDelete = [Event]() |
||||
eventIdsToCheck.forEach { eventId in |
||||
if let eventToCheck = dataStore.events.first(where: { $0.id == eventId }) { |
||||
if eventToCheck.tournaments.isEmpty && shouldEraseEmptyEvents { |
||||
eventsToDelete.append(eventToCheck) |
||||
} |
||||
} |
||||
} |
||||
|
||||
dataStore.events.delete(contentOfs: eventsToDelete) |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue