Work on patches

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

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

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

@ -28,22 +28,6 @@ struct ToolboxView: View {
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

Loading…
Cancel
Save