tournament: add: TOURNAMENT CAN START
This commit is contained in:
@ -51,6 +51,7 @@ class Tourmanent
|
||||
this.finished = response_data.finished;
|
||||
this.levels = response_data.levels;
|
||||
this.id = response_data.id
|
||||
this.state = this.get_state();
|
||||
}
|
||||
|
||||
leave(event)
|
||||
@ -66,10 +67,7 @@ class Tourmanent
|
||||
{
|
||||
if (!this.connected)
|
||||
return
|
||||
console.log(this.isParticipating);
|
||||
this.isParticipating = !this.isParticipating;
|
||||
console.log(this.isParticipating);
|
||||
this._socket.send(JSON.stringify({participate: this.isParticipating}));
|
||||
this._socket.send(JSON.stringify({participate: ""}));
|
||||
}
|
||||
|
||||
async join(receive_func, disconnect_func)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {client} from "../index.js";
|
||||
import {client, navigateTo} from "../index.js";
|
||||
import AbstractAuthentifiedView from "./abstracts/AbstractAuthentifiedView.js";
|
||||
|
||||
export default class extends AbstractAuthentifiedView
|
||||
@ -12,13 +12,24 @@ export default class extends AbstractAuthentifiedView
|
||||
pressButton()
|
||||
{
|
||||
this.tournament.toggle_participation();
|
||||
document.getElementById("button").value = this.tournament.isParticipating ? "Leave tournament" : "Join tournament";
|
||||
}
|
||||
|
||||
async receive(data)
|
||||
{
|
||||
if (data.detail === "nb_participants" || data.detail === "update_participants")
|
||||
document.getElementById("nb_participants").innerText = `${data.nb_participants} / ${this.tournament.nb_players}`
|
||||
if (data.detail === "go_to")
|
||||
navigateTo(data.url);
|
||||
if (data.detail === "is_participant")
|
||||
this.updateParticipating(data.is_participant)
|
||||
if (data.detail === "error")
|
||||
document.getElementById("display").innerText = data.error_message
|
||||
}
|
||||
|
||||
async updateParticipating(state)
|
||||
{
|
||||
document.getElementById("button").value = state ? `Leave ${this.tournament.name}` : `Join ${this.tournament.name}`;
|
||||
document.getElementById("display").innerText = state ? "You are a particpant" : "You are not a participant";
|
||||
}
|
||||
|
||||
async ondisconnect(event)
|
||||
@ -81,6 +92,7 @@ export default class extends AbstractAuthentifiedView
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="button" id="button" value="Join tournament" disabled>
|
||||
`
|
||||
<span id="display"></span>
|
||||
`
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user