diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 1fab51f..585f260 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -173,7 +173,6 @@ FFC1E10C2BAC7FB0008D6F59 /* ClubImportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC1E10B2BAC7FB0008D6F59 /* ClubImportView.swift */; }; FFC83D4F2BB807D100750834 /* RoundsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC83D4E2BB807D100750834 /* RoundsView.swift */; }; FFC83D512BB8087E00750834 /* RoundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC83D502BB8087E00750834 /* RoundView.swift */; }; - FFD783FD2B91B9ED000F62A6 /* AgendaDestinationPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD783FC2B91B9ED000F62A6 /* AgendaDestinationPickerView.swift */; }; FFD783FF2B91BA42000F62A6 /* PadelClubView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD783FE2B91BA42000F62A6 /* PadelClubView.swift */; }; FFD784022B91C1B4000F62A6 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD784012B91C1B4000F62A6 /* WelcomeView.swift */; }; FFD784042B91C280000F62A6 /* EmptyActivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD784032B91C280000F62A6 /* EmptyActivityView.swift */; }; @@ -402,7 +401,6 @@ FFC1E10B2BAC7FB0008D6F59 /* ClubImportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClubImportView.swift; sourceTree = ""; }; FFC83D4E2BB807D100750834 /* RoundsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundsView.swift; sourceTree = ""; }; FFC83D502BB8087E00750834 /* RoundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundView.swift; sourceTree = ""; }; - FFD783FC2B91B9ED000F62A6 /* AgendaDestinationPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgendaDestinationPickerView.swift; sourceTree = ""; }; FFD783FE2B91BA42000F62A6 /* PadelClubView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadelClubView.swift; sourceTree = ""; }; FFD784002B91BF79000F62A6 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; FFD784012B91C1B4000F62A6 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = ""; }; @@ -897,7 +895,6 @@ FFD784012B91C1B4000F62A6 /* WelcomeView.swift */, FF59FFB22B90EFAC0061EFF9 /* EventListView.swift */, FF5D0D8A2BB4D1E3005CB568 /* CalendarView.swift */, - FFD783FC2B91B9ED000F62A6 /* AgendaDestinationPickerView.swift */, ); path = Agenda; sourceTree = ""; @@ -1162,7 +1159,6 @@ FF1CBC1D2BB53DC10036DAAB /* Calendar+Extensions.swift in Sources */, FF967CF22BAECC0B00A9A3BD /* TeamScore.swift in Sources */, FF5D0D762BB428B2005CB568 /* ListRowViewModifier.swift in Sources */, - FFD783FD2B91B9ED000F62A6 /* AgendaDestinationPickerView.swift in Sources */, FF6EC9002B94794700EA7F5A /* PresentationContext.swift in Sources */, FFDB1C6D2BB2A02000F1E467 /* AppSettings.swift in Sources */, FF0EC5202BB16F680056B6D1 /* SwiftParser.swift in Sources */, diff --git a/PadelClub/ViewModel/AgendaDestination.swift b/PadelClub/ViewModel/AgendaDestination.swift index 2180486..b42e051 100644 --- a/PadelClub/ViewModel/AgendaDestination.swift +++ b/PadelClub/ViewModel/AgendaDestination.swift @@ -7,7 +7,7 @@ import Foundation -enum AgendaDestination: CaseIterable, Identifiable { +enum AgendaDestination: CaseIterable, Identifiable, Selectable { var id: Self { self } case activity @@ -30,6 +30,10 @@ enum AgendaDestination: CaseIterable, Identifiable { } } + func selectionLabel() -> String { + localizedTitleKey + } + var systemImage: String { switch self { case .activity: diff --git a/PadelClub/Views/Components/GenericDestinationPickerView.swift b/PadelClub/Views/Components/GenericDestinationPickerView.swift index 4c0ac5a..b8d2987 100644 --- a/PadelClub/Views/Components/GenericDestinationPickerView.swift +++ b/PadelClub/Views/Components/GenericDestinationPickerView.swift @@ -14,23 +14,26 @@ protocol Selectable { struct GenericDestinationPickerView: View { @Binding var selectedDestination: T? let destinations: [T] + let nilDestinationIsValid: Bool var body: some View { ScrollView(.horizontal) { HStack { - Button { - selectedDestination = nil - } label: { - Image(systemName: "wrench.and.screwdriver") - } - .padding() - .background { - Circle() - .fill(Color.white) - .opacity(selectedDestination == nil ? 1.0 : 0.5) + if nilDestinationIsValid { + Button { + selectedDestination = nil + } label: { + Image(systemName: "wrench.and.screwdriver") + } + .padding() + .background { + Circle() + .fill(Color.white) + .opacity(selectedDestination == nil ? 1.0 : 0.5) + } + .buttonStyle(.plain) } - .buttonStyle(.plain) - + ForEach(destinations) { destination in Button { selectedDestination = destination diff --git a/PadelClub/Views/GroupStage/GroupStagesView.swift b/PadelClub/Views/GroupStage/GroupStagesView.swift index deb21d0..9acadc9 100644 --- a/PadelClub/Views/GroupStage/GroupStagesView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesView.swift @@ -18,7 +18,7 @@ struct GroupStagesView: View { var body: some View { VStack(spacing: 0) { - GenericDestinationPickerView(selectedDestination: $selectedGroupStage, destinations: tournament.groupStages()) + GenericDestinationPickerView(selectedDestination: $selectedGroupStage, destinations: tournament.groupStages(), nilDestinationIsValid: true) switch selectedGroupStage { case .none: GroupStageSettingsView() diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index 379c1d7..1b53516 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -11,7 +11,7 @@ struct ActivityView: View { @EnvironmentObject var dataStore: DataStore @State private var searchText: String = "" - @State private var agendaDestination: AgendaDestination = .activity + @State private var agendaDestination: AgendaDestination? = .activity @State private var filterEnabled: Bool = false @State private var presentToolbar: Bool = false @@ -40,7 +40,7 @@ struct ActivityView: View { } var tournaments: [FederalTournamentHolder] { - switch agendaDestination { + switch agendaDestination! { case .activity: runningTournaments case .history: @@ -52,130 +52,129 @@ struct ActivityView: View { var body: some View { NavigationStack { - List { - Section { - AgendaDestinationPickerView(agendaDestination: $agendaDestination) - } - - switch agendaDestination { - case .activity: - EventListView(tournaments: runningTournaments, viewStyle: viewStyle) - case .history: - EventListView(tournaments: endedTournaments, viewStyle: viewStyle) - case .tenup: - EventListView(tournaments: federalTournaments, viewStyle: viewStyle) + VStack(spacing: 0) { + GenericDestinationPickerView(selectedDestination: $agendaDestination, destinations: AgendaDestination.allCases, nilDestinationIsValid: false) + List { + switch agendaDestination! { + case .activity: + EventListView(tournaments: runningTournaments, viewStyle: viewStyle) + case .history: + EventListView(tournaments: endedTournaments, viewStyle: viewStyle) + case .tenup: + EventListView(tournaments: federalTournaments, viewStyle: viewStyle) + } } - } - .overlay { - if isGatheringFederalTournaments { - ProgressView() - } else { - if tournaments.isEmpty { - if searchText.isEmpty == false { - ContentUnavailableView.search(text: searchText) - } else if filterEnabled { - ContentUnavailableView { - Text("Aucun résultat") - } description: { - Text("Description du filtre") - } actions: { - RowButtonView(title: "supprimer le filtre") { - filterEnabled.toggle() + .overlay { + if isGatheringFederalTournaments { + ProgressView() + } else { + if tournaments.isEmpty { + if searchText.isEmpty == false { + ContentUnavailableView.search(text: searchText) + } else if filterEnabled { + ContentUnavailableView { + Text("Aucun résultat") + } description: { + Text("Description du filtre") + } actions: { + RowButtonView(title: "supprimer le filtre") { + filterEnabled.toggle() + } } + } else { + _dataEmptyView() } - } else { - _dataEmptyView() } } } - } - //.searchable(text: $searchText) - .onAppear { presentToolbar = true } - .onDisappear { presentToolbar = false } - .sheet(item: $newTournament) { tournament in - EventCreationView(tournaments: [tournament]) - } - .refreshable { - if agendaDestination == .tenup { - federalTournaments.removeAll() - _gatherFederalTournaments() + //.searchable(text: $searchText) + .onAppear { presentToolbar = true } + .onDisappear { presentToolbar = false } + .sheet(item: $newTournament) { tournament in + EventCreationView(tournaments: [tournament]) } - } - .task { - if agendaDestination == .tenup - && dataStore.clubs.isEmpty == false - && federalTournaments.isEmpty { - _gatherFederalTournaments() + .refreshable { + if agendaDestination == .tenup { + federalTournaments.removeAll() + _gatherFederalTournaments() + } } - } - .onChange(of: agendaDestination) { - if agendaDestination == .tenup - && dataStore.clubs.isEmpty == false - && federalTournaments.isEmpty { - _gatherFederalTournaments() + .task { + if agendaDestination == .tenup + && dataStore.clubs.isEmpty == false + && federalTournaments.isEmpty { + _gatherFederalTournaments() + } } - } - .toolbar { - if presentToolbar { - ToolbarItem(placement: .status) { - VStack(spacing: -2) { - if filterEnabled { - Text("filtre actif") - } - if let _activityStatus = _activityStatus() { - Text(_activityStatus) - .foregroundStyle(.secondary) - } - } - .font(.footnote) + .onChange(of: agendaDestination) { + if agendaDestination == .tenup + && dataStore.clubs.isEmpty == false + && federalTournaments.isEmpty { + _gatherFederalTournaments() } - - - ToolbarItem(placement: .topBarLeading) { - Button { - switch viewStyle { - case .list: - viewStyle = .calendar - case .calendar: - viewStyle = .list + } + .toolbar { + if presentToolbar { + ToolbarItem(placement: .status) { + VStack(spacing: -2) { + if filterEnabled { + Text("filtre actif") + } + if let _activityStatus = _activityStatus() { + Text(_activityStatus) + .foregroundStyle(.secondary) + } } - } label: { - Image(systemName: "calendar.circle") - .resizable() - .scaledToFit() - .frame(minHeight: 28) + .font(.footnote) } - .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) - } - - ToolbarItem(placement: .topBarTrailing) { - Button { - newTournament = Tournament.newEmptyInstance() + + + ToolbarItem(placement: .topBarLeading) { + Button { + switch viewStyle { + case .list: + viewStyle = .calendar + case .calendar: + viewStyle = .list + } + } label: { + Image(systemName: "calendar.circle") + .resizable() + .scaledToFit() + .frame(minHeight: 28) + } + .symbolVariant(viewStyle == .calendar ? .fill : .none) - } label: { - Image(systemName: "plus.circle.fill") - .resizable() - .scaledToFit() - .frame(minHeight: 28) + // + // Button { + // filterEnabled.toggle() + // } label: { + // Image(systemName: "line.3.horizontal.decrease.circle") + // .resizable() + // .scaledToFit() + // .frame(minHeight: 28) + // } + // .symbolVariant(filterEnabled ? .fill : .none) + } + + ToolbarItem(placement: .topBarTrailing) { + Button { + newTournament = Tournament.newEmptyInstance() + + } label: { + Image(systemName: "plus.circle.fill") + .resizable() + .scaledToFit() + .frame(minHeight: 28) + } } } } - } - .navigationTitle(TabDestination.activity.title) - .navigationDestination(for: Tournament.self) { tournament in - TournamentView() - .environment(tournament) + .navigationTitle(TabDestination.activity.title) + .navigationDestination(for: Tournament.self) { tournament in + TournamentView() + .environment(tournament) + } } } } @@ -192,7 +191,7 @@ struct ActivityView: View { @ViewBuilder private func _dataEmptyView() -> some View { - switch agendaDestination { + switch agendaDestination! { case .activity: _runningEmptyView() case .history: diff --git a/PadelClub/Views/Navigation/Agenda/AgendaDestinationPickerView.swift b/PadelClub/Views/Navigation/Agenda/AgendaDestinationPickerView.swift deleted file mode 100644 index f32670b..0000000 --- a/PadelClub/Views/Navigation/Agenda/AgendaDestinationPickerView.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// AgendaDestinationPickerView.swift -// PadelClub -// -// Created by Razmig Sarkissian on 01/03/2024. -// - -import SwiftUI - -struct AgendaDestinationPickerView: View { - @Binding var agendaDestination: AgendaDestination - - var body: some View { - HStack { - ForEach(AgendaDestination.allCases) { screen in - - Button { - agendaDestination = screen - } label: { - Label(screen.localizedTitleKey, systemImage: screen.systemImage) - } - .padding() - .background { - Capsule(style: .continuous) - .fill(.white) - .opacity(screen == agendaDestination ? 1.0 : 0.5) - } - .labelStyle(.titleOnly) - .buttonStyle(.plain) - } - } - .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) - .listRowBackground(Color.clear) - } -} - -#Preview { - AgendaDestinationPickerView(agendaDestination: .constant(.activity)) -} diff --git a/PadelClub/Views/Round/RoundsView.swift b/PadelClub/Views/Round/RoundsView.swift index a1f1af5..eeb1609 100644 --- a/PadelClub/Views/Round/RoundsView.swift +++ b/PadelClub/Views/Round/RoundsView.swift @@ -18,7 +18,7 @@ struct RoundsView: View { var body: some View { VStack(spacing: 0) { - GenericDestinationPickerView(selectedDestination: $selectedRound, destinations: tournament.rounds()) + GenericDestinationPickerView(selectedDestination: $selectedRound, destinations: tournament.rounds(), nilDestinationIsValid: true) switch selectedRound { case .none: RoundSettingsView()