|
|
|
|
@ -17,9 +17,9 @@ struct ActivityView: View { |
|
|
|
|
@State private var presentToolbar: Bool = false |
|
|
|
|
@State private var newTournament: Tournament? |
|
|
|
|
@State private var viewStyle: AgendaDestination.ViewStyle = .list |
|
|
|
|
@State private var federalTournaments: [FederalTournament] = [] |
|
|
|
|
@State private var isGatheringFederalTournaments: Bool = false |
|
|
|
|
@State private var error: Error? |
|
|
|
|
@State private var uuid: UUID = UUID() |
|
|
|
|
|
|
|
|
|
var runningTournaments: [FederalTournamentHolder] { |
|
|
|
|
dataStore.tournaments.filter({ $0.endDate == nil }) |
|
|
|
|
@ -46,7 +46,7 @@ struct ActivityView: View { |
|
|
|
|
case .history: |
|
|
|
|
endedTournaments |
|
|
|
|
case .tenup: |
|
|
|
|
federalTournaments |
|
|
|
|
navigation.federalTournaments |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -63,7 +63,8 @@ struct ActivityView: View { |
|
|
|
|
case .history: |
|
|
|
|
EventListView(tournaments: endedTournaments, viewStyle: viewStyle) |
|
|
|
|
case .tenup: |
|
|
|
|
EventListView(tournaments: federalTournaments, viewStyle: viewStyle) |
|
|
|
|
EventListView(tournaments: navigation.federalTournaments, viewStyle: viewStyle) |
|
|
|
|
.id(uuid) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.overlay { |
|
|
|
|
@ -109,21 +110,22 @@ struct ActivityView: View { |
|
|
|
|
} |
|
|
|
|
.refreshable { |
|
|
|
|
if navigation.agendaDestination == .tenup { |
|
|
|
|
federalTournaments.removeAll() |
|
|
|
|
navigation.federalTournaments.removeAll() |
|
|
|
|
NetworkFederalService.shared.formId = "" |
|
|
|
|
_gatherFederalTournaments() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
if navigation.agendaDestination == .tenup |
|
|
|
|
&& dataStore.clubs.isEmpty == false |
|
|
|
|
&& federalTournaments.isEmpty { |
|
|
|
|
&& navigation.federalTournaments.isEmpty { |
|
|
|
|
_gatherFederalTournaments() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.onChange(of: navigation.agendaDestination) { |
|
|
|
|
if navigation.agendaDestination == .tenup |
|
|
|
|
&& dataStore.clubs.isEmpty == false |
|
|
|
|
&& federalTournaments.isEmpty { |
|
|
|
|
&& navigation.federalTournaments.isEmpty { |
|
|
|
|
_gatherFederalTournaments() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -159,16 +161,15 @@ struct ActivityView: View { |
|
|
|
|
} |
|
|
|
|
.symbolVariant(viewStyle == .calendar ? .fill : .none) |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// Button { |
|
|
|
|
// filterEnabled.toggle() |
|
|
|
|
// } label: { |
|
|
|
|
// Image(systemName: "line.3.horizontal.decrease.circle") |
|
|
|
|
// .resizable() |
|
|
|
|
// .scaledToFit() |
|
|
|
|
// .frame(minHeight: 28) |
|
|
|
|
// } |
|
|
|
|
// .symbolVariant(filterEnabled ? .fill : .none) |
|
|
|
|
Button { |
|
|
|
|
filterEnabled.toggle() |
|
|
|
|
} label: { |
|
|
|
|
Image(systemName: "line.3.horizontal.decrease.circle") |
|
|
|
|
.resizable() |
|
|
|
|
.scaledToFit() |
|
|
|
|
.frame(minHeight: 28) |
|
|
|
|
} |
|
|
|
|
.symbolVariant(filterEnabled ? .fill : .none) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
@ -195,16 +196,23 @@ struct ActivityView: View { |
|
|
|
|
|
|
|
|
|
private func _gatherFederalTournaments() { |
|
|
|
|
isGatheringFederalTournaments = true |
|
|
|
|
NetworkFederalService.shared.formId = "" |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await dataStore.clubs.filter { $0.code != nil }.concurrentForEach { club in |
|
|
|
|
federalTournaments += try await NetworkFederalService.shared.getClubFederalTournaments(page: 0, tournaments: [], club: club.name, codeClub: club.code!, startDate: .now.startOfMonth) |
|
|
|
|
let newTournaments = try await NetworkFederalService.shared.getClubFederalTournaments(page: 0, tournaments: [], club: club.name, codeClub: club.code!, startDate: .now.startOfMonth) |
|
|
|
|
|
|
|
|
|
newTournaments.forEach { tournament in |
|
|
|
|
if navigation.federalTournaments.contains(where: { $0.id == tournament.id }) == false { |
|
|
|
|
navigation.federalTournaments.append(tournament) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} catch { |
|
|
|
|
self.error = error |
|
|
|
|
} |
|
|
|
|
isGatheringFederalTournaments = false |
|
|
|
|
uuid = UUID() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -269,6 +277,7 @@ struct ActivityView: View { |
|
|
|
|
Text("Aucun tournoi n'a pu être récupéré via tenup.") |
|
|
|
|
} actions: { |
|
|
|
|
RowButtonView("Rafraîchir") { |
|
|
|
|
NetworkFederalService.shared.formId = "" |
|
|
|
|
_gatherFederalTournaments() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|