From 31ee86683a416cf293c4665ead2aad71f711c5c8 Mon Sep 17 00:00:00 2001 From: NiraliSonani Date: Thu, 28 Nov 2024 14:20:35 +0530 Subject: [PATCH] Added note, image in detail screen --- .../Repository/TransactionRepository.swift | 2 +- .../Expense Detail/ExpenseDetailsView.swift | 3 +- .../GroupTransactionDetailView.swift | 34 ++++++++++++++++++- .../GroupTransactionDetailViewModel.swift | 9 +++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Data/Data/Repository/TransactionRepository.swift b/Data/Data/Repository/TransactionRepository.swift index f5f0e2a0d..af417f5c1 100644 --- a/Data/Data/Repository/TransactionRepository.swift +++ b/Data/Data/Repository/TransactionRepository.swift @@ -28,7 +28,7 @@ public class TransactionRepository: ObservableObject { newTransaction.imageUrl = imageUrl } - try await store.addTransaction(document: transactionDocument, transaction: transaction) + try await store.addTransaction(document: transactionDocument, transaction: newTransaction) try await addActivityLogForTransaction(group: group, transaction: newTransaction, oldTransaction: transaction, type: .transactionAdded, members: members) return newTransaction diff --git a/Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift b/Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift index 0d6ece8cc..d35daddba 100644 --- a/Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift +++ b/Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift @@ -12,6 +12,7 @@ import Data struct ExpenseDetailsView: View { @StateObject var viewModel: ExpenseDetailsViewModel + @State private var showImageDisplayView = false var body: some View { @@ -206,7 +207,7 @@ private struct ExpenseInfoView: View { } } -private struct ExpenseNoteView: View { +struct ExpenseNoteView: View { let note: String diff --git a/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailView.swift b/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailView.swift index 0bf9d6f41..5a575ce1b 100644 --- a/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailView.swift +++ b/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailView.swift @@ -13,6 +13,8 @@ struct GroupTransactionDetailView: View { @StateObject var viewModel: GroupTransactionDetailViewModel + @State private var showImageDisplayView = false + var body: some View { GeometryReader { geometry in VStack(spacing: 0) { @@ -33,7 +35,27 @@ struct GroupTransactionDetailView: View { .multilineTextAlignment(.center) .padding(.top, 24) - Spacer() + if let imageUrl = viewModel.transaction?.imageUrl, !imageUrl.isEmpty { + VStack(spacing: 8) { + Text("Attachment:") + .font(.subTitle3()) + .foregroundStyle(disableText) + .frame(maxWidth: .infinity, alignment: .leading) + + ExpenseImageView(showImageDisplayView: $showImageDisplayView, imageUrl: imageUrl) + .frame(height: 140) + .frame(maxWidth: .infinity) + .cornerRadius(12) + } + .padding(.top, 24) + } + + if let note = viewModel.transaction?.note, !note.isEmpty { + ExpenseNoteView(note: note, handleNoteTap: viewModel.handleNoteTap) + .padding(.top, 16) + } + + VSpacer(24) } .padding(.horizontal, 16) } @@ -59,6 +81,11 @@ struct GroupTransactionDetailView: View { ) } } + .fullScreenCover(isPresented: $viewModel.showAddNoteEditor) { + NavigationStack { + AddNoteView(viewModel: AddNoteViewModel(group: viewModel.group, payment: viewModel.transaction, note: viewModel.paymentNote)) + } + } .toolbarRole(.editor) .toolbar { ToolbarItem(placement: .topBarLeading) { @@ -79,6 +106,11 @@ struct GroupTransactionDetailView: View { } } } + .navigationDestination(isPresented: $showImageDisplayView) { + if let imageUrl = viewModel.transaction?.imageUrl { + ExpenseImageZoomView(imageUrl: imageUrl, animationNamespace: Namespace()) + } + } } } diff --git a/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailViewModel.swift b/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailViewModel.swift index 22f07e99e..470466735 100644 --- a/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailViewModel.swift +++ b/Splito/UI/Home/Groups/Group/Group Options/Transactions/Transaction Detail/GroupTransactionDetailViewModel.swift @@ -15,10 +15,13 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject { @Inject private var groupRepository: GroupRepository @Inject private var transactionRepository: TransactionRepository + @Published var paymentNote: String = "" @Published private(set) var transaction: Transactions? @Published private(set) var transactionUsersData: [AppUser] = [] + @Published private(set) var viewState: ViewState = .loading + @Published var showAddNoteEditor = false @Published var showEditTransactionSheet = false var group: Groups? @@ -112,6 +115,12 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject { } // MARK: - User Actions + func handleNoteTap() { + guard let transaction, transaction.isActive, let userId = preference.user?.id, + let group, group.members.contains(userId) else { return } + showAddNoteEditor = true + } + func handleEditBtnAction() { guard validateUserPermission(operationText: "edited", action: "edit"), validateGroupMembers(action: "edited") else { return } showEditTransactionSheet = true