Skip to content

Commit

Permalink
Added note, image in detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Nov 28, 2024
1 parent dad9258 commit 31ee866
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Data/Data/Repository/TransactionRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Data
struct ExpenseDetailsView: View {

@StateObject var viewModel: ExpenseDetailsViewModel

@State private var showImageDisplayView = false

var body: some View {
Expand Down Expand Up @@ -206,7 +207,7 @@ private struct ExpenseInfoView: View {
}
}

private struct ExpenseNoteView: View {
struct ExpenseNoteView: View {

let note: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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) {
Expand All @@ -79,6 +106,11 @@ struct GroupTransactionDetailView: View {
}
}
}
.navigationDestination(isPresented: $showImageDisplayView) {
if let imageUrl = viewModel.transaction?.imageUrl {
ExpenseImageZoomView(imageUrl: imageUrl, animationNamespace: Namespace())
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31ee866

Please sign in to comment.