Skip to content

Commit

Permalink
Changed design & added different view & viewmodel for note
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Nov 27, 2024
1 parent 800ca70 commit b1e5cce
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 117 deletions.
8 changes: 4 additions & 4 deletions Data/Data/Model/Expense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public struct Expense: Codable, Hashable, Identifiable {
public var paidBy: [String: Double]
public let addedBy: String
public var updatedBy: String
public var notes: String
public var note: String
public var imageUrl: String?
public var splitTo: [String] // Reference to user ids involved in the split
public var splitType: SplitType
public var splitData: [String: Double]? // Use this to store percentage or share data
public var isActive: Bool

public init(name: String, amount: Double, date: Timestamp, paidBy: [String: Double], addedBy: String,
updatedBy: String, notes: String, imageUrl: String? = nil, splitTo: [String],
updatedBy: String, note: String, imageUrl: String? = nil, splitTo: [String],
splitType: SplitType = .equally, splitData: [String: Double]? = [:], isActive: Bool = true) {
self.name = name
self.amount = amount
self.date = date
self.paidBy = paidBy
self.addedBy = addedBy
self.updatedBy = updatedBy
self.notes = notes
self.note = note
self.imageUrl = imageUrl
self.splitTo = splitTo
self.splitType = splitType
Expand All @@ -49,7 +49,7 @@ public struct Expense: Codable, Hashable, Identifiable {
case paidBy = "paid_by"
case addedBy = "added_by"
case updatedBy = "updated_by"
case notes = "notes"
case note = "notes"
case imageUrl = "image_url"
case splitTo = "split_to"
case splitType = "split_type"
Expand Down
2 changes: 1 addition & 1 deletion Data/Data/Repository/ExpenseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ExpenseRepository: ObservableObject {
private func hasExpenseChanged(_ expense: Expense, oldExpense: Expense) -> Bool {
return oldExpense.name != expense.name || oldExpense.amount != expense.amount ||
oldExpense.date.dateValue() != expense.date.dateValue() || oldExpense.paidBy != expense.paidBy ||
oldExpense.updatedBy != expense.updatedBy || oldExpense.notes != expense.notes ||
oldExpense.updatedBy != expense.updatedBy || oldExpense.note != expense.note ||
oldExpense.imageUrl != expense.imageUrl || oldExpense.splitTo != expense.splitTo ||
oldExpense.splitType != expense.splitType || oldExpense.splitData != expense.splitData ||
oldExpense.isActive != expense.isActive
Expand Down
16 changes: 16 additions & 0 deletions Splito.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
0BF8F99614F85846D78DE106 /* Pods_Splito_SplitoUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2B9BBF3F71277A6AA5329CB /* Pods_Splito_SplitoUITests.framework */; };
210CC0382CF6DA7A0035682E /* ExpenseAddNoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210CC0372CF6DA7A0035682E /* ExpenseAddNoteView.swift */; };
210CC03B2CF6DA920035682E /* ExpenseAddNoteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210CC03A2CF6DA920035682E /* ExpenseAddNoteViewModel.swift */; };
213BA0602C0F465000116130 /* GroupSettleUpRouteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213BA05F2C0F465000116130 /* GroupSettleUpRouteView.swift */; };
213BA0662C11B70F00116130 /* HomeRouteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213BA0652C11B70F00116130 /* HomeRouteViewModel.swift */; };
214CF8492C2977E10044C188 /* CalculateExpensesFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 214CF8482C2977E10044C188 /* CalculateExpensesFunctions.swift */; };
Expand Down Expand Up @@ -153,6 +155,8 @@

/* Begin PBXFileReference section */
038CCD15E82A4E16A4AD213C /* Pods-Splito-SplitoUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Splito-SplitoUITests.release.xcconfig"; path = "Target Support Files/Pods-Splito-SplitoUITests/Pods-Splito-SplitoUITests.release.xcconfig"; sourceTree = "<group>"; };
210CC0372CF6DA7A0035682E /* ExpenseAddNoteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpenseAddNoteView.swift; sourceTree = "<group>"; };
210CC03A2CF6DA920035682E /* ExpenseAddNoteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpenseAddNoteViewModel.swift; sourceTree = "<group>"; };
213BA05F2C0F465000116130 /* GroupSettleUpRouteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupSettleUpRouteView.swift; sourceTree = "<group>"; };
213BA0652C11B70F00116130 /* HomeRouteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeRouteViewModel.swift; sourceTree = "<group>"; };
214CF8482C2977E10044C188 /* CalculateExpensesFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculateExpensesFunctions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -309,6 +313,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
210CC0392CF6DA7F0035682E /* Notes */ = {
isa = PBXGroup;
children = (
210CC0372CF6DA7A0035682E /* ExpenseAddNoteView.swift */,
210CC03A2CF6DA920035682E /* ExpenseAddNoteViewModel.swift */,
);
path = Notes;
sourceTree = "<group>";
};
21559CAA2CBD21850039F127 /* ActivityLog */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -505,6 +518,7 @@
D85E86EC2BB41B87002EDF76 /* SelectGroupView.swift */,
D85E86EE2BB41B9F002EDF76 /* SelectGroupViewModel.swift */,
21BA6D4B2C3BB64B0020ED04 /* Payer */,
210CC0392CF6DA7F0035682E /* Notes */,
);
path = "Detail Selection";
sourceTree = "<group>";
Expand Down Expand Up @@ -1060,6 +1074,7 @@
2177692D2C20316B009B3B37 /* GroupTransactionDetailViewModel.swift in Sources */,
D83344732C0F2D9500CD9F05 /* GroupPaymentView.swift in Sources */,
D83344582C0DD06F00CD9F05 /* GroupSettleUpView.swift in Sources */,
210CC03B2CF6DA920035682E /* ExpenseAddNoteViewModel.swift in Sources */,
D8E244BF2B98592C00C6C82A /* GroupHomeViewModel.swift in Sources */,
D833446C2C0F2D4200CD9F05 /* GroupWhoGettingPaidView.swift in Sources */,
D8D14A562BA189EC00F45FF2 /* JoinMemberView.swift in Sources */,
Expand Down Expand Up @@ -1089,6 +1104,7 @@
214CF8492C2977E10044C188 /* CalculateExpensesFunctions.swift in Sources */,
213BA0602C0F465000116130 /* GroupSettleUpRouteView.swift in Sources */,
D8AC26F72B84B12800CEAAD3 /* LoginView.swift in Sources */,
210CC0382CF6DA7A0035682E /* ExpenseAddNoteView.swift in Sources */,
D8CD952E2BD65F4500407B47 /* ExpenseSplitOptionsViewModel.swift in Sources */,
D85E86E32BAB06D9002EDF76 /* AddExpenseViewModel.swift in Sources */,
D8A7CA702BA484370014EC67 /* GroupSettingView.swift in Sources */,
Expand Down
7 changes: 5 additions & 2 deletions Splito/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"Add expense" : {

},
"Add notes" : {
"Add note" : {

},
"added" : {
Expand Down Expand Up @@ -220,6 +220,9 @@
},
"Are you sure you want to sign out?" : {
"extractionState" : "manual"
},
"Attachment:" : {

},
"Authentication failed" : {
"extractionState" : "manual"
Expand Down Expand Up @@ -506,7 +509,7 @@
"not involved" : {

},
"Notes" : {
"Note:" : {

},
"Ok" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "note-1_svgrepo.com.svg",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "note-1_svgrepo.com (1).svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 18 additions & 65 deletions Splito/UI/Home/Expense/AddExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ struct AddExpenseView: View {

AddExpenseFooterView(date: $viewModel.expenseDate, showImagePickerOptions: $viewModel.showImagePickerOptions,
expenseImage: viewModel.expenseImage, expenseImageUrl: viewModel.expenseImageUrl,
handleNotesTap: viewModel.handleNotesAction,
handleExpenseImageTap: viewModel.handleExpenseImageTap,
handleNoteTap: viewModel.handleNoteAction, handleExpenseImageTap: viewModel.handleExpenseImageTap,
handleActionSelection: viewModel.handleActionSelection(_:))
}
}
Expand Down Expand Up @@ -75,9 +74,13 @@ struct AddExpenseView: View {
)
}
}
.sheet(isPresented: $viewModel.showAddNotesEditor) {
.sheet(isPresented: $viewModel.showAddNoteEditor) {
NavigationStack {
ExpenseAddNotesView(expenseNotes: $viewModel.expenseNotes, onTap: viewModel.handleNotesSaveBtnTap)
if let groupId = viewModel.groupId, let expenseId = viewModel.expenseId {
ExpenseAddNoteView(viewModel: ExpenseAddNoteViewModel(
groupId: groupId, expenseId: expenseId, expenseNote: viewModel.expenseNote, handleSaveNoteTap: viewModel.handleNoteSaveBtnTap(note:)
))
}
}
}
.sheet(isPresented: $viewModel.showImagePicker) {
Expand Down Expand Up @@ -214,7 +217,7 @@ private struct AddExpenseFooterView: View {
let expenseImage: UIImage?
let expenseImageUrl: String?

let handleNotesTap: (() -> Void)
let handleNoteTap: (() -> Void)
let handleExpenseImageTap: (() -> Void)
let handleActionSelection: ((ActionsOfSheet) -> Void)

Expand All @@ -230,7 +233,7 @@ private struct AddExpenseFooterView: View {

ExpenseImagePickerView(image: expenseImage, imageUrl: expenseImageUrl, handleImageBtnTap: handleExpenseImageTap)

ExpenseNotesView(handleNotesTap: handleNotesTap)
ExpenseNoteView(handleNoteTap: handleNoteTap)
}
.padding(.vertical, 12)
.padding(.horizontal, 16)
Expand Down Expand Up @@ -275,71 +278,21 @@ private struct ExpenseImagePickerView: View {
}
}

struct ExpenseNotesView: View {
struct ExpenseNoteView: View {

let handleNotesTap: (() -> Void)
let handleNoteTap: (() -> Void)

var body: some View {
Image(systemName: "pencil.and.list.clipboard")
Image(.noteIcon)
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.onTapGestureForced(perform: handleNotesTap)
}
}

struct ExpenseAddNotesView: View {
@Environment(\.dismiss) var dismiss

@Binding var expenseNotes: String

let onTap: (() -> Void)

@State private var tempNotes: String
@FocusState private var isFocused: Bool

init(expenseNotes: Binding<String>, onTap: @escaping (() -> Void)) {
self._expenseNotes = expenseNotes
self.onTap = onTap
self._tempNotes = State(initialValue: expenseNotes.wrappedValue)
}

var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Notes")
.font(.buttonText(18))
.foregroundStyle(primaryText)

TextEditor(text: $tempNotes)
.font(.subTitle3())
.foregroundColor(primaryText)
.lineSpacing(5)
.multilineTextAlignment(.leading)
.scrollContentBackground(.hidden)
.focused($isFocused)
}
.padding(.horizontal, 16)
.background(surfaceColor)
.navigationTitle("Add notes")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("Cancel") {
dismiss()
}
.foregroundStyle(.blue)
.padding(4)
.onTouchGesture {
UIApplication.shared.endEditing()
handleNoteTap()
}
ToolbarItem(placement: .topBarTrailing) {
CheckmarkButton {
expenseNotes = tempNotes
onTap()
}
}
}
.onAppear {
isFocused = true
}
.background(container2Color)
.cornerRadius(8)
}
}
32 changes: 16 additions & 16 deletions Splito/UI/Home/Expense/AddExpenseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
@Inject private var expenseRepository: ExpenseRepository

@Published var expenseName = ""
@Published var expenseNotes: String = ""
@Published var expenseNote: String = ""
@Published private(set) var expenseImageUrl: String?
@Published private(set) var payerName = "You"

Expand All @@ -32,7 +32,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
@Published var showPayerSelection = false
@Published var showImagePickerOptions = false
@Published var showSplitTypeSelection = false
@Published var showAddNotesEditor = false
@Published var showAddNoteEditor = false
@Published private(set) var showLoader: Bool = false
@Published private(set) var sourceTypeIsCamera = false

Expand All @@ -52,8 +52,8 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
}
}

var expenseId: String?
private var groupId: String?
let expenseId: String?
let groupId: String?
private let router: Router<AppRoute>

init(router: Router<AppRoute>, groupId: String? = nil, expenseId: String? = nil) {
Expand All @@ -73,7 +73,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
}
}

// MARK: - Data Loading
// MARK: - Data Loading
private func fetchGroup(groupId: String) async {
do {
viewState = .loading
Expand Down Expand Up @@ -135,7 +135,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
splitType = expense.splitType
selectedPayers = expense.paidBy
expenseImageUrl = expense.imageUrl
expenseNotes = expense.notes
expenseNote = expense.note

if let splitData = expense.splitData {
self.splitData = splitData
Expand Down Expand Up @@ -179,7 +179,6 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {

// MARK: - User Actions
extension AddExpenseViewModel {

private func updatePayerName() {
Task {
if selectedPayers.count == 1 {
Expand Down Expand Up @@ -215,13 +214,13 @@ extension AddExpenseViewModel {
showImagePickerOptions = true
}

func handleNotesAction() {
UIApplication.shared.endEditing()
showAddNotesEditor = true
func handleNoteAction() {
showAddNoteEditor = true
}

func handleNotesSaveBtnTap() {
showAddNotesEditor = false
func handleNoteSaveBtnTap(note: String) {
showAddNoteEditor = false
self.expenseNote = note
}

func handleActionSelection(_ action: ActionsOfSheet) {
Expand Down Expand Up @@ -375,8 +374,9 @@ extension AddExpenseViewModel {

private func handleAddExpenseAction(userId: String, group: Groups) async -> Bool {
let expense = Expense(name: expenseName.trimming(spaces: .leadingAndTrailing), amount: expenseAmount,
date: Timestamp(date: expenseDate), paidBy: selectedPayers, addedBy: userId, updatedBy: userId,
notes: expenseNotes, splitTo: (splitType == .equally) ? selectedMembers : splitData.map({ $0.key }),
date: Timestamp(date: expenseDate), paidBy: selectedPayers, addedBy: userId,
updatedBy: userId, note: expenseNote.trimming(spaces: .leadingAndTrailing),
splitTo: (splitType == .equally) ? selectedMembers : splitData.map({ $0.key }),
splitType: splitType, splitData: splitData)

return await addExpense(group: group, expense: expense)
Expand Down Expand Up @@ -416,7 +416,7 @@ extension AddExpenseViewModel {
newExpense.amount = expenseAmount
newExpense.date = Timestamp(date: expenseDate)
newExpense.updatedBy = userId
newExpense.notes = expenseNotes
newExpense.note = expenseNote.trimming(spaces: .leadingAndTrailing)

if selectedPayers.count == 1, let payerId = selectedPayers.keys.first {
newExpense.paidBy = [payerId: expenseAmount]
Expand Down Expand Up @@ -463,7 +463,7 @@ extension AddExpenseViewModel {
private func hasExpenseChanged(_ expense: Expense, oldExpense: Expense) -> Bool {
return oldExpense.name != expense.name || oldExpense.amount != expense.amount ||
oldExpense.date.dateValue() != expense.date.dateValue() || oldExpense.paidBy != expense.paidBy ||
oldExpense.notes != expense.notes || oldExpense.imageUrl != expense.imageUrl ||
oldExpense.note != expense.note || oldExpense.imageUrl != expense.imageUrl ||
oldExpense.splitTo != expense.splitTo || oldExpense.splitType != expense.splitType ||
oldExpense.splitData != expense.splitData || oldExpense.isActive != expense.isActive
}
Expand Down
Loading

0 comments on commit b1e5cce

Please sign in to comment.