Skip to content

Commit 6f90ebe

Browse files
committed
Disable voting when comments are loading
1 parent 0854af3 commit 6f90ebe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Features/Comments/Sources/Comments/CommentsComponents.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct CommentsContentView: View {
3838
PostHeader(
3939
post: post,
4040
votingViewModel: votingViewModel,
41+
isLoadingComments: viewModel.isLoading,
4142
showThumbnails: viewModel.showThumbnails,
4243
onLinkTap: { handleLinkTap() },
4344
onPostUpdated: { updatedPost in
@@ -57,6 +58,7 @@ struct CommentsContentView: View {
5758
view.swipeActions(edge: .leading, allowsFullSwipe: true) {
5859
if post.upvoted && post.voteLinks?.unvote != nil {
5960
Button {
61+
guard !viewModel.isLoading else { return }
6062
Task {
6163
var mutablePost = post
6264
await votingViewModel.unvote(post: &mutablePost)
@@ -74,8 +76,10 @@ struct CommentsContentView: View {
7476
}
7577
.tint(.orange)
7678
.accessibilityLabel("Unvote")
79+
.disabled(viewModel.isLoading)
7780
} else {
7881
Button {
82+
guard !viewModel.isLoading else { return }
7983
Task {
8084
var mutablePost = post
8185
await votingViewModel.upvote(post: &mutablePost)
@@ -90,6 +94,7 @@ struct CommentsContentView: View {
9094
}
9195
.tint(AppColors.upvotedColor)
9296
.accessibilityLabel("Upvote")
97+
.disabled(viewModel.isLoading)
9398
}
9499
}
95100
}
@@ -218,6 +223,7 @@ struct CommentsForEach: View {
218223
struct PostHeader: View {
219224
let post: Post
220225
let votingViewModel: VotingViewModel
226+
let isLoadingComments: Bool
221227
let showThumbnails: Bool
222228
let onLinkTap: () -> Void
223229
let onPostUpdated: @Sendable (Post) -> Void
@@ -256,6 +262,7 @@ struct PostHeader: View {
256262
}
257263

258264
private func handleUpvote() async -> Bool {
265+
guard !isLoadingComments else { return false }
259266
guard votingViewModel.canVote(item: post), !post.upvoted else { return false }
260267

261268
var mutablePost = post
@@ -272,6 +279,7 @@ struct PostHeader: View {
272279
}
273280

274281
private func handleUnvote() async -> Bool {
282+
guard !isLoadingComments else { return true }
275283
guard votingViewModel.canUnvote(item: post), post.upvoted else { return true }
276284

277285
var mutablePost = post

0 commit comments

Comments
 (0)