Skip to content

Commit 07e5e97

Browse files
authored
[Feature] Add support for showing current poll comment on alert (#891)
1 parent d710ba9 commit 07e5e97

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6+
### ✅ Added
7+
- Add support for showing current poll comment on alert [#891](https://github.com/GetStream/stream-chat-swiftui/pull/891)
8+
69
### 🔄 Changed
710

811
# [4.82.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.82.0)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/Polls/PollCommentsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct PollCommentsView<Factory: ViewFactory>: View {
7777
}
7878
.padding()
7979
}
80+
.background(Color(colors.background).ignoresSafeArea())
8081
.alertBanner(
8182
isPresented: $viewModel.errorShown,
8283
action: viewModel.refresh

Sources/StreamChatSwiftUI/ChatChannel/MessageList/Polls/PollCommentsViewModel.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class PollCommentsViewModel: ObservableObject, PollVoteListControllerDelegate {
7676
self?.errorShown = true
7777
}
7878
}
79-
newCommentText = ""
8079
}
8180

8281
func onAppear(comment: PollVote) {
@@ -93,13 +92,18 @@ class PollCommentsViewModel: ObservableObject, PollVoteListControllerDelegate {
9392
) {
9493
if animateChanges {
9594
withAnimation {
96-
self.comments = Array(self.commentsController.votes)
95+
self.updateCommentList()
9796
}
9897
} else {
99-
comments = Array(commentsController.votes)
98+
updateCommentList()
10099
}
101100
}
102101

102+
private func updateCommentList() {
103+
comments = Array(commentsController.votes)
104+
newCommentText = comments.first(where: { $0.user?.id == chatClient.currentUserId })?.answerText ?? ""
105+
}
106+
103107
private func loadComments() {
104108
guard !loadingComments, !commentsController.hasLoadedAllVotes else { return }
105109
loadingComments = true

StreamChatSwiftUITests/Tests/ChatChannel/PollCommentsViewModel_Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class PollCommentsViewModel_Tests: StreamChatTestCase {
5252
XCTAssertFalse(viewModel.showsAddCommentButton)
5353
}
5454

55-
func test_addComment_whenSuccess_thenCommentTextReset() {
55+
func test_addComment_whenSuccess() {
5656
// Given
5757
let pollController = makePollController()
5858

@@ -66,7 +66,7 @@ final class PollCommentsViewModel_Tests: StreamChatTestCase {
6666

6767
// Then
6868
XCTAssertTrue(pollController.castPollVote_called)
69-
XCTAssertEqual("", viewModel.newCommentText)
69+
XCTAssertEqual("A", viewModel.newCommentText)
7070
}
7171

7272
// MARK: - Test Data
Loading

0 commit comments

Comments
 (0)