|
|
@ -62,15 +62,14 @@ class UnitsManagerVM : ObservableObject {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func load() async throws {
|
|
|
|
func load() async throws {
|
|
|
|
print("Loading VM...")
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try await original.load()
|
|
|
|
try await original.load()
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.model = self.original.data
|
|
|
|
self.model = self.original.data
|
|
|
|
self.unitsVM = self.original.units.map { UnitVM(unit: $0) }
|
|
|
|
self.unitsVM = self.original.units.map { UnitVM(unit: $0) }
|
|
|
|
print("VM loaded")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
// DEV: this should be replaced with proper error handling before ever going to prod
|
|
|
|
print("ERROR: Failed to load VM...")
|
|
|
|
print("ERROR: Failed to load VM...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -79,14 +78,13 @@ class UnitsManagerVM : ObservableObject {
|
|
|
|
guard let index = unitsVM.firstIndex(where: { $0.id == unitVM.id }) else { return }
|
|
|
|
guard let index = unitsVM.firstIndex(where: { $0.id == unitVM.id }) else { return }
|
|
|
|
let updatedUnit = unitsVM[index].model
|
|
|
|
let updatedUnit = unitsVM[index].model
|
|
|
|
original.units[index].update(from: updatedUnit)
|
|
|
|
original.units[index].update(from: updatedUnit)
|
|
|
|
print("Saving VM...")
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try await original.save()
|
|
|
|
try await original.save()
|
|
|
|
print("VM saved")
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.model = self.original.data
|
|
|
|
self.model = self.original.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
// DEV: this should be replaced with proper error handling before ever going to prod
|
|
|
|
print("ERROR: Failed to save VM...")
|
|
|
|
print("ERROR: Failed to save VM...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|