Skip to content

Commit 5aa4007

Browse files
Broadcast estimates
1 parent 22225e3 commit 5aa4007

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

assets/js/socket.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,31 @@ presence.onSync(() => {
1414
const user = document.createElement('li')
1515
user.setAttribute('class', id)
1616
user.appendChild(document.createTextNode(id))
17+
18+
const estimate = document.createElement('span')
19+
estimate.setAttribute('class', 'user-estimate')
20+
user.appendChild(estimate)
21+
1722
users.appendChild(user)
1823
})
1924
})
2025

21-
channel.join()
22-
.receive('ok', resp => { console.log('Joined successfully', resp) })
23-
.receive('error', resp => { console.log('Unable to join', resp) })
26+
if (window.pointingParty.username) {
27+
channel.join ()
28+
.receive('ok', resp => { console.log('Joined successfully', resp) })
29+
.receive('error', resp => { console.log('Unable to join', resp) })
30+
}
31+
32+
const calculateButton = document.querySelector('.calculate-points')
33+
calculateButton.addEventListener('click', event => {
34+
const storyPoints = document.querySelector('.story-points')
35+
channel.push('user_estimated', { points: storyPoints.value })
36+
})
37+
38+
39+
channel.on("user_estimated", ({ points, userId }) => {
40+
const user = document.querySelector(`.${userId} .user-estimate`)
41+
user.innerHTML = points
42+
})
2443

2544
export default socket

lib/pointing_party_web/channels/room_channel.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ defmodule PointingPartyWeb.RoomChannel do
1515

1616
{:noreply, socket}
1717
end
18+
19+
def handle_in("user_estimated", %{"points" => points}, socket) do
20+
broadcast!(socket, "user_estimated", %{points: points, userId: socket.assigns.username})
21+
22+
{:noreply, socket}
23+
end
1824
end

lib/pointing_party_web/templates/card/index.html.eex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
<div class="form-group text-left">
1010
<div class="form-row align-items-center">
1111
<div class="col-2">
12-
<label for="storyPoints">Story Points</label>
13-
<select class="form-control" id="storyPoints">
12+
<label for="story-points">Story Points</label>
13+
<select class="form-control story-points" id="story-points">
1414
<%= Enum.map(@points, fn point -> %>
15-
<%= if @card.points == point do %>
16-
<option selected="selected'"><%= point %></option>
17-
<% else %>
18-
<option><%= point %></option>
19-
<% end %>
15+
<option><%= point %></option>
2016
<% end) %>
2117
</select>
2218
</div>
2319
</div>
2420
</div>
25-
<a href="#" class="btn btn-primary">Calculate Points</a>
21+
<a href="#" class="btn btn-primary calculate-points">Calculate Points</a>
2622
</div>
2723

2824
<div class="card-footer text-muted">

priv/static/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)