From 54fc430dce7dd08a723aff460c1a4df4712498d0 Mon Sep 17 00:00:00 2001 From: Alexis Drai Date: Sat, 10 Jun 2023 16:29:52 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=87=20Remove=20some=20print=20statemen?= =?UTF-8?q?ts,=20improve=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Graduator/Graduator/Model/UnitsManager.swift | 6 ++---- Graduator/Graduator/View/Cells/SubjectViewCell.swift | 7 ++++--- Graduator/Graduator/View/Views/UnitView.swift | 6 ++++-- Graduator/Graduator/ViewModel/UnitsManagerVM.swift | 6 ++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Graduator/Graduator/Model/UnitsManager.swift b/Graduator/Graduator/Model/UnitsManager.swift index f075abb..fac8c28 100644 --- a/Graduator/Graduator/Model/UnitsManager.swift +++ b/Graduator/Graduator/Model/UnitsManager.swift @@ -18,21 +18,19 @@ struct UnitsManager { } mutating func load() async throws { - print("Loading...") do { self.units = try await store.load() - print("Units loaded") } catch { + // DEV: this should be replaced with proper error handling before ever going to prod print("ERROR: Failed to load...") } } func save() async throws { - print("Saving...") do { try await store.save(units: units) - print("Units saved") } catch { + // DEV: this should be replaced with proper error handling before ever going to prod print("ERROR: Failed to save...") } } diff --git a/Graduator/Graduator/View/Cells/SubjectViewCell.swift b/Graduator/Graduator/View/Cells/SubjectViewCell.swift index dc6f7f9..54fc022 100644 --- a/Graduator/Graduator/View/Cells/SubjectViewCell.swift +++ b/Graduator/Graduator/View/Cells/SubjectViewCell.swift @@ -18,8 +18,8 @@ struct SubjectViewCell: View { HStack { VStack { // 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 - // unitsManagerVM.updateUnit(unitVM) ? If so, how to even fix that? + // 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 + // when 'cancel' is hit, it would be nice to reset these two values as well, like a user might expect HStack { TextField("", text: $subjectVM.model.name) .disabled(!unitsManagerVM.isAllEditable) @@ -42,7 +42,8 @@ struct SubjectViewCell: View { unitVM.updateSubject(subjectVM) try await unitsManagerVM.updateUnit(unitVM) } 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)") } } } diff --git a/Graduator/Graduator/View/Views/UnitView.swift b/Graduator/Graduator/View/Views/UnitView.swift index 01a13d0..3a4650a 100644 --- a/Graduator/Graduator/View/Views/UnitView.swift +++ b/Graduator/Graduator/View/Views/UnitView.swift @@ -89,7 +89,8 @@ struct UnitView: View { unitVM.updateAllSubjects() try await unitsManagerVM.updateUnit(unitVM) } 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) showingForm = false } 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 { diff --git a/Graduator/Graduator/ViewModel/UnitsManagerVM.swift b/Graduator/Graduator/ViewModel/UnitsManagerVM.swift index 27e3ab3..296a6d4 100644 --- a/Graduator/Graduator/ViewModel/UnitsManagerVM.swift +++ b/Graduator/Graduator/ViewModel/UnitsManagerVM.swift @@ -62,15 +62,14 @@ class UnitsManagerVM : ObservableObject { } func load() async throws { - print("Loading VM...") do { try await original.load() DispatchQueue.main.async { self.model = self.original.data self.unitsVM = self.original.units.map { UnitVM(unit: $0) } - print("VM loaded") } } catch { + // DEV: this should be replaced with proper error handling before ever going to prod 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 } let updatedUnit = unitsVM[index].model original.units[index].update(from: updatedUnit) - print("Saving VM...") do { try await original.save() - print("VM saved") DispatchQueue.main.async { self.model = self.original.data } } catch { + // DEV: this should be replaced with proper error handling before ever going to prod print("ERROR: Failed to save VM...") } }