Skip to content

Commit

Permalink
[Modify] 리스너 구독취소 함수 작성 및 리스너 데이터 수정 시 다음 작동 코드 일단 주석처리 #173
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrsky2010 committed Apr 18, 2024
1 parent 256a8ac commit 7956306
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion JUDA_iOS/JUDA/View/Posts/PostsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ struct PostsView: View {
case .DrinkDetailWithUsedTo(let drink, let usedTo):
DrinkDetailView(drink: drink, usedTo: usedTo)
.modifier(TabBarHidden())
//
case .PostDetail(let postUserType,
let post,
let usedTo):
Expand Down
21 changes: 14 additions & 7 deletions JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,21 @@ extension PostViewModel {

snapshot.documentChanges.forEach { diff in
do {
if diff.type == .added {
let post = try diff.document.data(as: PostField.self)
self.posts.append(Post(postField: post, likedUsersID: []))
}
// if diff.type == .added {
// let postField = try diff.document.data(as: PostField.self)
// self.posts.append(Post(postField: postField, likedUsersID: []))
// }

if diff.type == .modified {

let postField = try diff.document.data(as: PostField.self)
if let index = self.posts.firstIndex(where: { $0.postField.postID == postField.postID }) {
self.posts[index].postField = postField
}
}

if diff.type == .removed {
let post = try diff.document.data(as: PostField.self)
if let index = self.posts.firstIndex(where: { $0.postField.postID == post.postID }) {
let postField = try diff.document.data(as: PostField.self)
if let index = self.posts.firstIndex(where: { $0.postField.postID == postField.postID }) {
self.posts.remove(at: index)
}
}
Expand All @@ -335,6 +338,10 @@ extension PostViewModel {
}
}
}

func stopListening() {
listener?.remove()
}
}

// MARK: - Report Upload
Expand Down

0 comments on commit 7956306

Please sign in to comment.