File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
lib/pointing_party_web/channels Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,7 @@ defmodule PointingPartyWeb.RoomChannel do
3131 end
3232
3333 def handle_in ( "next_card" , % { "points" => points } , socket ) do
34- # update the current card's `points` value to `points` from the message payload
35- # update state by setting the current card to the next card
34+ save_vote_next_card ( points , socket )
3635 # broadcast the "new_card" message with a payload of %{card: new_current_card}
3736
3837 { :reply , :ok , socket }
@@ -47,4 +46,24 @@ defmodule PointingPartyWeb.RoomChannel do
4746 |> assign ( :unvoted , cards )
4847 |> assign ( :current , first )
4948 end
49+
50+ defp save_vote_next_card ( points , socket ) do
51+ # save the points on the card
52+ latest_card =
53+ socket . assigns
54+ |> Map . get ( :current )
55+ |> Map . put ( :points , points )
56+
57+ # fetch the next card from the list of cards
58+ { next , remaining } =
59+ socket . assigns
60+ |> Map . get ( :unvoted )
61+ |> List . pop_at ( 0 )
62+
63+ # update socket state by moving the current card into `voted` and the next card into `current_card`
64+ socket
65+ |> assign ( :unvoted , remaining )
66+ |> assign ( :current , next )
67+ |> assign ( :voted , [ latest_card | socket . assigns [ :voted ] ] )
68+ end
5069end
You can’t perform that action at this time.
0 commit comments