From f3909c9055a3b331a11fdfbc65f22c6cc1b1153e Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 30 Apr 2024 14:39:51 +0200 Subject: [PATCH] Adds isDeleted property to tournaments --- PadelClub/Data/Tournament.swift | 2 ++ .../Views/Navigation/Agenda/ActivityView.swift | 4 ++-- .../Views/Navigation/Agenda/EventListView.swift | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 089d4e5..782a6dd 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -43,6 +43,7 @@ class Tournament : ModelObject, Storable { var entryFee: Double? var payment: TournamentPayment? = nil var additionalEstimationDuration: Int = 0 + var isDeleted: Bool = false @ObservationIgnored var navigationPath: [Screen] = [] @@ -1116,6 +1117,7 @@ extension Tournament { case _teamsPerGroupStage = "teamsPerGroupStage" case _entryFee = "entryFee" case _additionalEstimationDuration = "additionalEstimationDuration" + case _isDeleted = "isDeleted" } } diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index 90c2cee..17d9ab8 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -22,12 +22,12 @@ struct ActivityView: View { @State private var uuid: UUID = UUID() var runningTournaments: [FederalTournamentHolder] { - dataStore.tournaments.filter({ $0.endDate == nil }) + dataStore.tournaments.filter({ $0.endDate == nil && $0.isDeleted == false }) .filter({ federalDataViewModel.isTournamentValidForFilters($0) }) } var endedTournaments: [Tournament] { - dataStore.tournaments.filter({ $0.endDate != nil }) + dataStore.tournaments.filter({ $0.endDate != nil && $0.isDeleted == false }) .filter({ federalDataViewModel.isTournamentValidForFilters($0) }) .sorted(using: SortDescriptor(\.startDate, order: .reverse)) } diff --git a/PadelClub/Views/Navigation/Agenda/EventListView.swift b/PadelClub/Views/Navigation/Agenda/EventListView.swift index 227cb55..c8267d3 100644 --- a/PadelClub/Views/Navigation/Agenda/EventListView.swift +++ b/PadelClub/Views/Navigation/Agenda/EventListView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import LeStorage struct EventListView: View { @EnvironmentObject var dataStore: DataStore @@ -65,6 +66,7 @@ struct EventListView: View { do { try await federalDataViewModel.gatherTournaments(clubs: dataStore.clubs.filter { $0.code != nil }, startDate: startDate, endDate: startDate.endOfMonth) } catch { + Logger.error(error) // self.error = error } // isGatheringFederalTournaments = false @@ -83,7 +85,6 @@ struct EventListView: View { return result } - private func _listView(_ tournaments: [FederalTournamentHolder]) -> some View { ForEach(tournaments, id: \.holderId) { tournamentHolder in @@ -101,7 +102,15 @@ struct EventListView: View { } .swipeActions(edge: .trailing, allowsFullSwipe: true) { Button(role: .destructive) { - try? dataStore.tournaments.delete(instance: tournament) + + tournament.isDeleted = true + do { + try dataStore.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + +// try? dataStore.tournaments.delete(instance: tournament) } label: { LabelDelete() }