Skip to content

Commit

Permalink
bugfix: unvote
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Lasek committed Sep 26, 2024
1 parent 780a4b2 commit 863bd6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Sources/WishKit/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public struct Configuration {
public var emailField: EmailField = .optional

public var commentSection: Display = .show

public var allowUndoVote: Bool = false

init(
statusBadgeDisplay: Display = .hide,
Expand Down
16 changes: 11 additions & 5 deletions Sources/WishKit/SwiftUI/WishView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ struct WishView: View {
@Binding
private var voteCount: Int

@State
private var hasVoted = false

private let wishResponse: WishResponse

private let voteActionCompletion: () -> Void
Expand Down Expand Up @@ -164,12 +161,21 @@ struct WishView: View {
}

private func voteAction() {

if wishResponse.state == .implemented {
alertModel.alertReason = .alreadyImplemented
alertModel.showAlert = true
return
}

let userUUID = UUIDManager.getUUID()

let hasVoted = wishResponse.votingUsers.contains(where: { user in user.uuid == userUUID })

if (hasVoted) && WishKit.config.allowUndoVote == false {
alertModel.alertReason = .alreadyVoted
alertModel.showAlert = true
return
}

let request = VoteWishRequest(wishId: wishResponse.id)

Expand All @@ -192,7 +198,7 @@ struct WishView: View {
extension WishView {
var arrowColor: Color {
let userUUID = UUIDManager.getUUID()
if wishResponse.votingUsers.contains(where: { user in user.uuid == userUUID }) || hasVoted {
if wishResponse.votingUsers.contains(where: { user in user.uuid == userUUID }) {
return WishKit.theme.primaryColor
}

Expand Down

0 comments on commit 863bd6f

Please sign in to comment.