Skip to content

Commit

Permalink
Made common headerView&Checked type while store comment in log
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Jan 10, 2025
1 parent f9a79d2 commit 9b03602
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 51 deletions.
4 changes: 4 additions & 0 deletions BaseStyle/BaseStyle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
21BEF8A72C6399BA00FBC9CF /* BottomSheetHeightModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21BEF8A62C6399BA00FBC9CF /* BottomSheetHeightModifier.swift */; };
21D26E232CA199630090488B /* CapsuleButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D26E222CA199610090488B /* CapsuleButton.swift */; };
21D614792CAD527D00779F1E /* NavigationTitleTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D614782CAD527D00779F1E /* NavigationTitleTextView.swift */; };
21F41AFA2D30110C00D37DBB /* SectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F41AF92D30110C00D37DBB /* SectionHeaderView.swift */; };
5DAEE93D2D2208132D031984 /* Pods_BaseStyleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4AFAF996FB5C233D40D81D5 /* Pods_BaseStyleTests.framework */; };
A40018A9B957803B8105BEA5 /* Pods_BaseStyle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 174198EE4AF2FC82DADEB060 /* Pods_BaseStyle.framework */; };
D82174BE2BBAD86D00DB42C3 /* ProfileImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82174BD2BBAD86D00DB42C3 /* ProfileImageView.swift */; };
Expand Down Expand Up @@ -78,6 +79,7 @@
21BEF8A62C6399BA00FBC9CF /* BottomSheetHeightModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomSheetHeightModifier.swift; sourceTree = "<group>"; };
21D26E222CA199610090488B /* CapsuleButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleButton.swift; sourceTree = "<group>"; };
21D614782CAD527D00779F1E /* NavigationTitleTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTitleTextView.swift; sourceTree = "<group>"; };
21F41AF92D30110C00D37DBB /* SectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderView.swift; sourceTree = "<group>"; };
2CE85328C46B183FC3F074A3 /* Pods-BaseStyle.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BaseStyle.release.xcconfig"; path = "Target Support Files/Pods-BaseStyle/Pods-BaseStyle.release.xcconfig"; sourceTree = "<group>"; };
5BDB5B9B63CFD771230CD759 /* Pods-BaseStyleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BaseStyleTests.release.xcconfig"; path = "Target Support Files/Pods-BaseStyleTests/Pods-BaseStyleTests.release.xcconfig"; sourceTree = "<group>"; };
CC9EC1F1C0A5A0821118E6CA /* Pods-BaseStyleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BaseStyleTests.debug.xcconfig"; path = "Target Support Files/Pods-BaseStyleTests/Pods-BaseStyleTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -273,6 +275,7 @@
219F43D82CCA4A7000729C67 /* RestoreButton.swift */,
D8EB5E942CF8B12B005B68D9 /* ZoomableImageView.swift */,
D8FFD5C62CF44DBC009A0667 /* AttachmentZoomView.swift */,
21F41AF92D30110C00D37DBB /* SectionHeaderView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -532,6 +535,7 @@
D8D14A502BA090F000F45FF2 /* ShareSheetView.swift in Sources */,
D8E244B52B972AD200C6C82A /* EmptyRouteView.swift in Sources */,
D8D42A842B85D07C009B345D /* Spacers.swift in Sources */,
21F41AFA2D30110C00D37DBB /* SectionHeaderView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
28 changes: 28 additions & 0 deletions BaseStyle/BaseStyle/Views/SectionHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SectionHeaderView.swift
// Splito
//
// Created by Nirali Sonani on 09/01/25.
//

import SwiftUI

public struct SectionHeaderView: View {

let text: String
let font: Font
let textColor: Color

public init(text: String, font: Font = .subTitle3(), textColor: Color = disableText) {
self.text = text
self.font = font
self.textColor = textColor
}

public var body: some View {
Text(text.localized)
.font(font)
.foregroundStyle(textColor)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
3 changes: 2 additions & 1 deletion Data/Data/Repository/ExpenseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ public class ExpenseRepository: ObservableObject {

let amount = expense.getCalculatedSplitAmountOf(member: memberId)
let actionUserName = (memberId == currentUser.id) ? "You" : currentUser.nameWithLastInitial
let comment = context.type == .expenseCommentAdded ? expense.comments?.last?.comment : nil

return ActivityLog(type: context.type, groupId: groupId, activityId: expenseId, groupName: group.name,
actionUserName: actionUserName, recordedOn: Timestamp(date: Date()),
expenseName: expense.name, comment: expense.comments?.last?.comment, amount: amount)
expenseName: expense.name, comment: comment, amount: amount)
}

private func addActivityLog(context: ActivityLogContext) async -> Error? {
Expand Down
6 changes: 0 additions & 6 deletions Splito/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@
},
"Choose from Library" : {

},
"Comments:" : {

},
"Contact Support" : {
"extractionState" : "manual"
Expand Down Expand Up @@ -579,9 +576,6 @@
},
"not involved" : {

},
"Note:" : {

},
"Ok" : {
"extractionState" : "manual"
Expand Down
34 changes: 12 additions & 22 deletions Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import SwiftUI
import BaseStyle
import Data
import FirebaseFirestore

struct ExpenseDetailsView: View {

Expand All @@ -24,7 +23,7 @@ struct ExpenseDetailsView: View {
} else if case .loading = viewModel.viewState {
LoaderView()
} else {
ScrollViewReader { scrollViewProxy in
ScrollViewReader { proxy in
ScrollView {
VStack(alignment: .leading, spacing: 0) {
ExpenseHeaderView(viewModel: viewModel)
Expand All @@ -33,10 +32,7 @@ struct ExpenseDetailsView: View {

if let imageUrl = viewModel.expense?.imageUrl, !imageUrl.isEmpty {
VStack(spacing: 8) {
Text("Attachment:")
.font(.subTitle3())
.foregroundStyle(disableText)
.frame(maxWidth: .infinity, alignment: .leading)
SectionHeaderView(text: "Attachment:")

AttachmentContainerView(showImageDisplayView: $showImageDisplayView, imageUrl: imageUrl)
.frame(height: 140)
Expand All @@ -62,7 +58,7 @@ struct ExpenseDetailsView: View {
.id("scrollToNewestComment")
.onChange(of: viewModel.expense?.comments?.count) { _ in
withAnimation {
scrollViewProxy.scrollTo("scrollToNewestComment", anchor: .bottom) // Scroll to the end when a new comment is added
proxy.scrollTo("scrollToNewestComment", anchor: .bottom) // Scroll to the end when a new comment is added
}
}
.frame(maxWidth: isIpad ? 600 : nil, alignment: .center)
Expand Down Expand Up @@ -131,18 +127,15 @@ private struct CommentListView: View {
var body: some View {
if let comments = viewModel.expense?.comments, !comments.isEmpty {
VStack(spacing: 8) {
Text("Comments:")
.font(.subTitle3())
.foregroundStyle(disableText)
.frame(maxWidth: .infinity, alignment: .leading)
SectionHeaderView(text: "Comments:")
.padding(.horizontal, 16)

ForEach(comments.uniqued(), id: \.id) { comment in
var memberName: String {
let user = viewModel.getMemberDataBy(id: comment.commentedBy)
return viewModel.preference.user?.id == user?.id ? "You" : user?.fullName ?? "someone"
}

CommentCellView(comment: comment, memberName: memberName,
memberProfileUrl: viewModel.getMemberDataBy(id: comment.commentedBy)?.imageUrl,
isLastComment: comments.last?.id == comment.id)
Expand All @@ -155,10 +148,10 @@ private struct CommentListView: View {

private struct CommentCellView: View {

var comment: Comments
var memberName: String
var memberProfileUrl: String?
var isLastComment: Bool
let comment: Comments
let memberName: String
let memberProfileUrl: String?
let isLastComment: Bool

var body: some View {
HStack(alignment: .top, spacing: 16) {
Expand Down Expand Up @@ -234,9 +227,9 @@ private struct AddCommentTextField: View {
}

private struct SendButtonView: View {

let showLoader: Bool

let onClick: () -> Void

var body: some View {
Expand Down Expand Up @@ -376,10 +369,7 @@ struct NoteContainerView: View {

var body: some View {
VStack(spacing: 8) {
Text("Note:")
.font(.subTitle3())
.foregroundStyle(disableText)
.frame(maxWidth: .infinity, alignment: .leading)
SectionHeaderView(text: "Note:")

Text(note)
.font(.subTitle2())
Expand Down
47 changes: 25 additions & 22 deletions Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,34 +125,37 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {
}

func onSendCommentBtnTap() {
guard let expense, let group, let userId = preference.user?.id else { return }
if !expense.isActive || !group.isActive || !group.members.contains(userId) {
guard let expense, let group, let userId = preference.user?.id,
expense.isActive && group.isActive && group.members.contains(userId) else {
showAlertFor(title: "Error",
message: "You do not have permission to add a comment on this expense, Sorry!")
return
}

addComment()
}

private func addComment() {
guard let expense, let group, let userId = preference.user?.id else { return }

Task { [weak self] in
guard let self else { return }
do {
self.showLoader = true

self?.showLoader = true
var newExpense = expense
var updatedComments = expense.comments ?? []
updatedComments.append(Comments(id: UUID().uuidString, comment: self.comment.trimming(spaces: .leadingAndTrailing), commentedBy: userId))
newExpense.comments = updatedComments

let updatedExpense = try await expenseRepository.updateExpense(group: group, expense: newExpense,
oldExpense: expense, type: .expenseCommentAdded)
newExpense.comments?.append(Comments(id: UUID().uuidString,
comment: self?.comment.trimming(spaces: .leadingAndTrailing) ?? "",
commentedBy: userId))
let updatedExpense = try await self?.expenseRepository.updateExpense(group: group, expense: newExpense,
oldExpense: expense, type: .expenseCommentAdded)
NotificationCenter.default.post(name: .updateExpense, object: updatedExpense)

self.comment = ""
self.showLoader = false
LogD("AddExpenseViewModel: \(#function) Expense updated successfully.")
self?.comment = ""
self?.showLoader = false
LogD("ExpenseDetailsViewModel: \(#function) Expense comment added successfully.")
} catch {
self.showLoader = false
LogE("AddExpenseViewModel: \(#function) Failed to update expense \(expenseId): \(error).")
self.showToastForError()
self?.showLoader = false
LogE("ExpenseDetailsViewModel: \(#function) Failed to add comment: \(error).")
self?.showToastForError()
}
}
}
Expand All @@ -177,7 +180,7 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {
guard let group, group.isActive else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.showAlertFor(title: "Error",
message: "The group associated with this expense has been deleted, so it cannot be restored.")
message: "The group associated with this expense has been deleted, so it cannot be restored.")
}
return
}
Expand Down Expand Up @@ -264,7 +267,7 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {
guard let userId = preference.user?.id, let group, group.members.contains(userId) else {
DispatchQueue.main.async { [weak self] in
self?.showAlertFor(title: "Error",
message: "This expense could not be \(operationText). You do not have permission to \(action) this expense, Sorry!")
message: "This expense could not be \(operationText). You do not have permission to \(action) this expense, Sorry!")
}
return false
}
Expand Down Expand Up @@ -301,8 +304,8 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {

@objc private func getUpdatedExpense(notification: Notification) {
guard let updatedExpense = notification.object as? Expense else { return }
Task {
await processExpense(expense: updatedExpense)
Task { [weak self] in
await self?.processExpense(expense: updatedExpense)
}
}

Expand Down

0 comments on commit 9b03602

Please sign in to comment.