Implement the capacity from a user to remove himself from the sharing

sync3
Laurent 1 month ago
parent 4a07d430b7
commit 08cf60629b
  1. 21
      PadelClub/Views/Tournament/TournamentView.swift

@ -12,6 +12,7 @@ import PadelClubData
struct TournamentView: View {
@EnvironmentObject var dataStore: DataStore
@Environment(\.dismiss) private var dismiss
@Environment(NavigationViewModel.self) var navigation: NavigationViewModel
@State var tournament: Tournament
@ -337,7 +338,12 @@ struct TournamentView: View {
}
} else {
Button {
DataStore.shared.deleteTournament(self.tournament, noSync: true)
self._removeUserFromSharing()
// StoreCenter.main.setAuthorizedUsers(for: <#T##T#>, users: T##[String])
//
// DataStore.shared.deleteTournament(self.tournament, noSync: true)
} label: {
Label("Quitter la supervision", systemImage: "person.crop.circle.badge.minus")
}
@ -355,6 +361,19 @@ struct TournamentView: View {
}
}
fileprivate func _removeUserFromSharing() {
guard let userId = StoreCenter.main.userId else { return }
var users = StoreCenter.main.authorizedUsers(for: self.tournament.id)
users.removeAll(where: { $0 == userId })
do {
try StoreCenter.main.setAuthorizedUsers(for: self.tournament, users: users)
DataStore.shared.deleteTournament(self.tournament, noSync: true)
dismiss()
} catch {
Logger.error(error)
}
}
private func _save() {
dataStore.tournaments.addOrUpdate(instance: tournament)
}

Loading…
Cancel
Save