diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 5129223..f2b27ae 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3262,7 +3262,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3307,7 +3307,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 3; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/AppSettings.swift b/PadelClub/Data/AppSettings.swift index 60be3e3..4dbc2db 100644 --- a/PadelClub/Data/AppSettings.swift +++ b/PadelClub/Data/AppSettings.swift @@ -29,6 +29,18 @@ final class AppSettings: MicroStorable { var nationalCup: Bool var dayDuration: Int? var dayPeriod: DayPeriod + + func lastDataSourceDate() -> Date? { + guard let lastDataSource else { return nil } + return URL.importDateFormatter.date(from: lastDataSource) + } + + func localizedLastDataSource() -> String? { + guard let lastDataSource else { return nil } + guard let date = URL.importDateFormatter.date(from: lastDataSource) else { return nil } + + return date.monthYearFormatted + } func resetSearch() { tournamentAges = Set() diff --git a/PadelClub/ViewModel/SearchViewModel.swift b/PadelClub/ViewModel/SearchViewModel.swift index e55dff7..be8a85c 100644 --- a/PadelClub/ViewModel/SearchViewModel.swift +++ b/PadelClub/ViewModel/SearchViewModel.swift @@ -36,8 +36,7 @@ class SearchViewModel: ObservableObject, Identifiable { @Published var filterSelectionEnabled: Bool = false @Published var isPresented: Bool = false @Published var selectedAgeCategory: FederalTournamentAge = .unlisted - - var mostRecentDate: Date? = nil + @Published var mostRecentDate: Date? = nil var selectionIsOver: Bool { if allowSingleSelection && selectedPlayers.count == 1 { diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 8c9dd36..e8fbfd0 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -129,7 +129,7 @@ struct ToolboxView: View { Section { NavigationLink { - SelectablePlayerListView(isPresented: false) + SelectablePlayerListView(isPresented: false, lastDataSource: true) } label: { Label("Rechercher un joueur", systemImage: "person.fill.viewfinder") } diff --git a/PadelClub/Views/Shared/SelectablePlayerListView.swift b/PadelClub/Views/Shared/SelectablePlayerListView.swift index 9b61575..00a4836 100644 --- a/PadelClub/Views/Shared/SelectablePlayerListView.swift +++ b/PadelClub/Views/Shared/SelectablePlayerListView.swift @@ -24,23 +24,19 @@ struct SelectablePlayerListView: View { @StateObject private var searchViewModel: SearchViewModel @Environment(\.dismiss) var dismiss - var lastDataSource: String? { - dataStore.appSettings.lastDataSource - } - @State private var searchText: String = "" - var mostRecentDate: Date? { - guard let lastDataSource else { return nil } - return URL.importDateFormatter.date(from: lastDataSource) - } - - init(allowSelection: Int = 0, isPresented: Bool = true, searchField: String? = nil, dataSet: DataSet = .national, filterOption: PlayerFilterOption = .all, hideAssimilation: Bool = false, ascending: Bool = true, sortOption: SortOption = .rank, fromPlayer: FederalPlayer? = nil, codeClub: String? = nil, ligue: String? = nil, showFemaleInMaleAssimilation: Bool = false, tokens: [SearchToken] = [], hidePlayers: [String]? = nil, playerSelectionAction: PlayerSelectionAction? = nil, contentUnavailableAction: ContentUnavailableAction? = nil) { + + init(allowSelection: Int = 0, isPresented: Bool = true, searchField: String? = nil, dataSet: DataSet = .national, filterOption: PlayerFilterOption = .all, hideAssimilation: Bool = false, ascending: Bool = true, sortOption: SortOption = .rank, fromPlayer: FederalPlayer? = nil, codeClub: String? = nil, ligue: String? = nil, showFemaleInMaleAssimilation: Bool = false, tokens: [SearchToken] = [], hidePlayers: [String]? = nil, lastDataSource: Bool = false, playerSelectionAction: PlayerSelectionAction? = nil, contentUnavailableAction: ContentUnavailableAction? = nil) { self.allowSelection = allowSelection self.playerSelectionAction = playerSelectionAction self.contentUnavailableAction = contentUnavailableAction self.searchText = searchField ?? "" let searchViewModel = SearchViewModel() searchViewModel.tokens = tokens + if lastDataSource { + searchViewModel.mostRecentDate = DataStore.shared.appSettings.lastDataSourceDate() + } + searchViewModel.searchText = searchField ?? "" searchViewModel.debouncableText = searchField ?? "" searchViewModel.showFemaleInMaleAssimilation = showFemaleInMaleAssimilation @@ -59,6 +55,18 @@ struct SelectablePlayerListView: View { _searchViewModel = StateObject(wrappedValue: searchViewModel) } + var enableSourceCheck: Binding { + Binding { + searchViewModel.mostRecentDate != nil + } set: { value in + if value == false { + searchViewModel.mostRecentDate = nil + } else { + searchViewModel.mostRecentDate = dataStore.appSettings.lastDataSourceDate() + } + } + } + var body: some View { VStack(spacing: 0) { if importObserver.isImportingFile() == false { @@ -73,6 +81,13 @@ struct SelectablePlayerListView: View { } .pickerStyle(.segmented) Menu { + if let lastDataSource = dataStore.appSettings.localizedLastDataSource() { + Section { + Toggle(isOn: enableSourceCheck) { + Text("Limité à \(lastDataSource)") + } + } + } Section { ForEach(SourceFileManager.getSortOption()) { option in Toggle(isOn: .init(get: { @@ -191,7 +206,6 @@ struct SelectablePlayerListView: View { } } .onAppear { - searchViewModel.mostRecentDate = mostRecentDate if searchViewModel.tokens.isEmpty && searchText.isEmpty { searchViewModel.debouncableText.removeAll() searchViewModel.searchText.removeAll()