Work on patches

club_update
Laurent 1 year ago
parent 3ce02088f9
commit d702a53b11
  1. 20
      PadelClub/Data/DataStore.swift
  2. 28
      PadelClub/Utils/Patcher.swift
  3. 16
      PadelClub/Views/Navigation/Toolbox/ToolboxView.swift

@ -118,15 +118,25 @@ class DataStore: ObservableObject {
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> { } else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> {
self._fixMissingEventCreatorIfNecessary(eventsCollection) self._fixMissingEventCreatorIfNecessary(eventsCollection)
} }
if Store.main.collectionsAllLoaded() {
Patcher.applyAllWhenApplicable()
}
} }
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection<Club>) { fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection<Club>) {
for club in clubsCollection { do {
if let userId = StoreCenter.main.userId, club.creator == nil { for club in clubsCollection {
club.creator = userId if let userId = StoreCenter.main.userId, club.creator == nil {
self.userStorage.item()?.addClub(club) club.creator = userId
clubsCollection.writeChangeAndInsertOnServer(instance: club) self.userStorage.item()?.addClub(club)
try self.userStorage.update()
clubsCollection.writeChangeAndInsertOnServer(instance: club)
}
} }
} catch {
Logger.error(error)
} }
} }

@ -19,20 +19,20 @@ enum Patch: String, CaseIterable {
class Patcher { class Patcher {
// static func applyIfNeeded() { static func applyAllWhenApplicable() {
// for patch in Patch.allCases { for patch in Patch.allCases {
// if UserDefaults.standard.value(forKey: patch.id) == nil { self.patchIfPossible(patch)
// do { }
// try self.applyPatch(patch) }
// UserDefaults.standard.setValue(true, forKey: patch.id)
// } catch { static func patchIfPossible(_ patch: Patch) {
// Logger.error(error) if UserDefaults.standard.value(forKey: patch.id) == nil {
// } self._applyPatch(patch)
// } UserDefaults.standard.setValue(true, forKey: patch.id)
// } }
// } }
static func applyPatch(_ patch: Patch) { fileprivate static func _applyPatch(_ patch: Patch) {
switch patch { switch patch {
case .alexisLeDu: self._patchAlexisLeDu() case .alexisLeDu: self._patchAlexisLeDu()
case .importDataFromDev: self._importDataFromDev() case .importDataFromDev: self._importDataFromDev()

@ -28,22 +28,6 @@ struct ToolboxView: View {
SupportButtonView(contentIsUnavailable: false) SupportButtonView(contentIsUnavailable: false)
if StoreCenter.main.userId == "94f45ed2-8938-4c32-a4b6-e4525073dd33" {
Button {
Patcher.applyPatch(.alexisLeDu)
} label: {
Text("Patch")
}
}
#if DEBUG
Button {
Patcher.applyPatch(.importDataFromDev)
} label: {
Text("Import from dev")
}
#endif
} }
#if DEBUG #if DEBUG

Loading…
Cancel
Save