Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As new votes come in, or vote weights are edited, the vote tally on the ballot detail page should update. #43

Open
zorn opened this issue Aug 18, 2024 · 1 comment

Comments

@zorn
Copy link
Owner

zorn commented Aug 18, 2024

Additionally, as votes update, the table should update.

@zorn
Copy link
Owner Author

zorn commented Aug 18, 2024

This works now, because as a single live view instance updates a votes it refreshes the vote list, but we should solve this with PubSub.

def handle_event("save", params, socket) do
%{"vote_id" => vote_id, "weight" => weight} = params
vote = assert_vote_id(socket, vote_id)
%{ballot: ballot} = socket.assigns
case RankedVoting.update_vote(ballot, vote, %{weight: weight}) do
{:ok, _vote} ->
socket
|> update(:vote_forms, fn current_vote_forms ->
Map.delete(current_vote_forms, vote_id)
end)
# TODO: This is a expensive, and we might consider a more efficient
# solution, maybe using streams?
|> assign_votes()
|> noreply()
{:error, changeset} ->
socket
|> put_flash(:error, "Could not update vote.")
|> update(:vote_forms, fn current_vote_forms ->
Map.put(current_vote_forms, vote_id, to_form(changeset))
end)
|> noreply()
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant