From e4c756d3fdc3e97c4802bc4edd9ec00a7103b6d8 Mon Sep 17 00:00:00 2001 From: NiraliSonani Date: Tue, 17 Dec 2024 15:59:48 +0530 Subject: [PATCH] Show toast & manage optional unwrap --- Splito.xcodeproj/project.pbxproj | 2 +- Splito/UI/Home/Expense/AddExpenseViewModel.swift | 7 ++++--- .../Expense Split Option/ExpenseSplitOptionsTabView.swift | 0 .../Expense Split Option/ExpenseSplitOptionsView.swift | 0 .../ExpenseSplitOptionsViewModel.swift | 0 Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift | 1 + 6 files changed, 6 insertions(+), 4 deletions(-) rename Splito/UI/Home/Expense/{ => Detail Selection}/Expense Split Option/ExpenseSplitOptionsTabView.swift (100%) rename Splito/UI/Home/Expense/{ => Detail Selection}/Expense Split Option/ExpenseSplitOptionsView.swift (100%) rename Splito/UI/Home/Expense/{ => Detail Selection}/Expense Split Option/ExpenseSplitOptionsViewModel.swift (100%) diff --git a/Splito.xcodeproj/project.pbxproj b/Splito.xcodeproj/project.pbxproj index 69e392bb4..ed41222fc 100644 --- a/Splito.xcodeproj/project.pbxproj +++ b/Splito.xcodeproj/project.pbxproj @@ -513,7 +513,6 @@ D85E86E22BAB06D9002EDF76 /* AddExpenseViewModel.swift */, D85E86F02BB41CBA002EDF76 /* Detail Selection */, D856C7302BCFD2080008A341 /* Expense Detail */, - D8CD952A2BD65E6400407B47 /* Expense Split Option */, 210CC0392CF6DA7F0035682E /* Note */, ); path = Expense; @@ -525,6 +524,7 @@ D85E86EC2BB41B87002EDF76 /* SelectGroupView.swift */, D85E86EE2BB41B9F002EDF76 /* SelectGroupViewModel.swift */, 21BA6D4B2C3BB64B0020ED04 /* Payer */, + D8CD952A2BD65E6400407B47 /* Expense Split Option */, ); path = "Detail Selection"; sourceTree = ""; diff --git a/Splito/UI/Home/Expense/AddExpenseViewModel.swift b/Splito/UI/Home/Expense/AddExpenseViewModel.swift index 852b1db58..ea6a6527a 100644 --- a/Splito/UI/Home/Expense/AddExpenseViewModel.swift +++ b/Splito/UI/Home/Expense/AddExpenseViewModel.swift @@ -262,7 +262,8 @@ extension AddExpenseViewModel { self.showToastFor(toast: ToastPrompt(type: .warning, title: "Whoops!", message: "Please select a group to get payer list.")) return } - if let userId = preference.user?.id, selectedPayers == [:] || selectedPayers[userId] == 0 { + + if let userId = preference.user?.id, selectedPayers == [:] || (selectedPayers[userId] ?? 0) == 0 { selectedPayers = [userId: expenseAmount] } showPayerSelection = true @@ -320,8 +321,8 @@ extension AddExpenseViewModel { } func handleSaveAction() async -> Bool { - if let userId = preference.user?.id, selectedPayers == [:] || selectedPayers[userId] == 0 || - (selectedPayers.count == 1 && selectedPayers[userId] != expenseAmount) { + if let userId = preference.user?.id, selectedPayers == [:] || (selectedPayers[userId] ?? 0) == 0 || + (selectedPayers.count == 1 && (selectedPayers[userId] ?? 0) != expenseAmount) { selectedPayers = [userId: expenseAmount] } diff --git a/Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsTabView.swift b/Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsTabView.swift similarity index 100% rename from Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsTabView.swift rename to Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsTabView.swift diff --git a/Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsView.swift b/Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsView.swift similarity index 100% rename from Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsView.swift rename to Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsView.swift diff --git a/Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsViewModel.swift b/Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsViewModel.swift similarity index 100% rename from Splito/UI/Home/Expense/Expense Split Option/ExpenseSplitOptionsViewModel.swift rename to Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsViewModel.swift diff --git a/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift b/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift index fd83859c6..6e806fa6c 100644 --- a/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift +++ b/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift @@ -64,6 +64,7 @@ public class EmailLoginViewModel: BaseViewModel, ObservableObject { } catch { isLoginInProgress = false LogE("EmailLoginViewModel: \(#function) Error fetching user: \(error).") + showToastForError() } } }