🔇 Remove some print statements, improve comments

pull/8/head
Alexis Drai 2 years ago
parent 644616784a
commit 54fc430dce

@ -18,21 +18,19 @@ struct UnitsManager {
} }
mutating func load() async throws { mutating func load() async throws {
print("Loading...")
do { do {
self.units = try await store.load() self.units = try await store.load()
print("Units loaded")
} catch { } catch {
// DEV: this should be replaced with proper error handling before ever going to prod
print("ERROR: Failed to load...") print("ERROR: Failed to load...")
} }
} }
func save() async throws { func save() async throws {
print("Saving...")
do { do {
try await store.save(units: units) try await store.save(units: units)
print("Units saved")
} catch { } catch {
// DEV: this should be replaced with proper error handling before ever going to prod
print("ERROR: Failed to save...") print("ERROR: Failed to save...")
} }
} }

@ -18,8 +18,8 @@ struct SubjectViewCell: View {
HStack { HStack {
VStack { VStack {
// FIXME (later, maybe) when getting updated from the UnitView, these two changes are persisted right away instead of waiting for user // FIXME (later, maybe) when getting updated from the UnitView, these two changes are persisted right away instead of waiting for user
// to confirm changes. Or is it rather that we were updating these fields, and then changing the grade, thus calling // to confirm changes. They just don't get brought into the main UnitsManager, so the average is not recalculated when a unit's weight changes
// unitsManagerVM.updateUnit(unitVM) ? If so, how to even fix that? // when 'cancel' is hit, it would be nice to reset these two values as well, like a user might expect
HStack { HStack {
TextField("", text: $subjectVM.model.name) TextField("", text: $subjectVM.model.name)
.disabled(!unitsManagerVM.isAllEditable) .disabled(!unitsManagerVM.isAllEditable)
@ -42,7 +42,8 @@ struct SubjectViewCell: View {
unitVM.updateSubject(subjectVM) unitVM.updateSubject(subjectVM)
try await unitsManagerVM.updateUnit(unitVM) try await unitsManagerVM.updateUnit(unitVM)
} catch { } catch {
print("Failed to update grade: \(error)") // DEV: this should be replaced with proper error handling before ever going to prod
print("ERROR: Failed to update grade: \(error)")
} }
} }
} }

@ -89,7 +89,8 @@ struct UnitView: View {
unitVM.updateAllSubjects() unitVM.updateAllSubjects()
try await unitsManagerVM.updateUnit(unitVM) try await unitsManagerVM.updateUnit(unitVM)
} catch { } catch {
print("Failed to update unit: \(error)") // DEV: this should be replaced with proper error handling before ever going to prod
print("ERROR: Failed to update unit: \(error)")
} }
} }
}) { }) {
@ -118,7 +119,8 @@ struct UnitView: View {
try await unitsManagerVM.updateUnit(unitVM) try await unitsManagerVM.updateUnit(unitVM)
showingForm = false showingForm = false
} catch { } catch {
print("Failed to create unit: \(error)") // DEV: this should be replaced with proper error handling before ever going to prod
print("ERROR: Failed to create unit: \(error)")
} }
} }
} else { } else {

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

Loading…
Cancel
Save