Adds isDeleted property to tournaments

multistore
Laurent 2 years ago
parent d5bb06a76d
commit f3909c9055
  1. 2
      PadelClub/Data/Tournament.swift
  2. 4
      PadelClub/Views/Navigation/Agenda/ActivityView.swift
  3. 13
      PadelClub/Views/Navigation/Agenda/EventListView.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"
}
}

@ -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))
}

@ -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()
}

Loading…
Cancel
Save