FEATURE: Allow users to remove their vote (PR #14459)

They can use the remove vote button or select the same option again for single choice polls.


Do we need to push it if it’s undefined?

Ditto ^^

Should probably use the DELETE verb and a different route on the server to handle the removal of a vote

Why couldn’t they remove their vote on multiple choices polls?

I think we still need this since we should be using a different route for the vote removal

This handles the case when a user clicks again on the option. I implemented this just for single choice polls because it is a bad user experience for multiple choice polls.

I see. Nice.

How does the button look like? Would it be better to make it red?

There is already a red button to close the poll.

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

I’m personally not a huge fan of extending the DiscoursePoll::Poll.vote method to be able to remove vote because the original intend of the method is to cast a vote. A new method like DiscoursePoll::Poll.remove_vote would make it much clearer IMO.

This is not related to your change but I wished we had use a custom error class instead. This is rescuing all errors whether they are related to poll vote or not.

@nbianca I really like the refactor that you did here. Things are properly organised and alot easier to follow.

Why is vote called options? :thinking:

Love that you’ve made a method for each operations :clap:

I would have put the current_user as the 1st parameter but that’s nitpicking.

Since you’re not using post anywhere else, there’s no point in loading it using find_by. Maybe just use exists?

Why was this removed?

I am not sure exactly why, but this is the name in JavaScript too. It makes sense because a vote is nothing more than a set of selected poll options.

It was unused.