11import { Socket , Presence } from 'phoenix'
2- import updateUsers from './users'
3-
42const socket = new Socket ( '/socket' , { params : { username : window . pointingParty . username } } )
53socket . connect ( )
64
7- const channel = socket . channel ( 'room:lobby' , { } )
8- const presence = new Presence ( channel )
9-
10- presence . onSync ( ( ) => updateUsers ( presence ) )
11-
12- let driving = false
13-
14- if ( window . pointingParty . username ) {
15- channel . join ( )
16- . receive ( 'ok' , resp => { console . log ( 'Joined successfully' , resp ) } )
17- . receive ( 'error' , resp => { console . log ( 'Unable to join' , resp ) } )
18- }
5+ let driving = false ;
196
207const startButton = document . querySelector ( '.start-button' )
218startButton . addEventListener ( 'click' , e => {
229 driving = true ;
23- channel . push ( 'start_pointing' , { } )
10+ // send 'start_pointing' message to the channel here
2411} )
2512
2613const nextCardButtons = document . getElementsByClassName ( 'next-card' )
2714for ( let i = 0 ; i < nextCardButtons . length ; i ++ ) {
2815 nextCardButtons [ i ] . addEventListener ( 'click' , e => {
29- channel . push ( 'finalized_points' , { points : e . target . value } )
16+ // send 'finalized_points' message to the channel here
3017 } )
3118}
3219
3320document
3421 . querySelector ( '.calculate-points' )
3522 . addEventListener ( 'click' , event => {
3623 const storyPoints = document . querySelector ( '.story-points' )
37- channel . push ( 'user_estimated' , { points : storyPoints . value } )
24+ // send 'user_estimated' to the channel here
3825 } )
3926
40- channel . on ( 'new_card' , state => {
27+ // call the relevant function defined below when you receive the following events from the channel:
28+ // 'next_card'
29+ // 'winner'
30+ // 'tie'
31+
32+ function showCard ( state ) {
4133 document
4234 . querySelector ( '.start-button' )
4335 . style . display = "none"
@@ -59,20 +51,9 @@ channel.on('new_card', state => {
5951 document
6052 . querySelector ( '.ticket-description' )
6153 . innerHTML = state . card . description
62- } )
63-
64- const renderVotingResults = function ( template ) {
65- const pointContainer = document . querySelector ( '.points-container' )
66- renderTemplate ( pointContainer , template )
67-
68- document
69- . querySelector ( '.next-card' )
70- . addEventListener ( 'click' , e => {
71- channel . push ( 'finalized_points' , { points : e . target . value } )
72- } )
7354}
7455
75- channel . on ( 'winner' , state => {
56+ function showWinner ( state ) {
7657 document
7758 . querySelector ( '.winner' )
7859 . style . display = "block"
@@ -88,9 +69,9 @@ channel.on('winner', state => {
8869 document
8970 . querySelector ( '.next-card' )
9071 . disabled = ! driving
91- } )
72+ }
9273
93- channel . on ( 'tie' , state => {
74+ function showTie ( state ) {
9475 document
9576 . querySelector ( '.tie' )
9677 . style . display = "block"
@@ -121,6 +102,6 @@ channel.on('tie', state => {
121102 . querySelector ( '.tie' )
122103 . getElementsByClassName ( 'next-card' ) [ 1 ]
123104 . disabled = ! driving
124- } )
105+ }
125106
126107export default socket
0 commit comments