diff --git a/frontend/js/frontend.js b/frontend/js/frontend.js
index a68e5e5..c046149 100644
--- a/frontend/js/frontend.js
+++ b/frontend/js/frontend.js
@@ -1,3 +1,5 @@
+const FAIRHOPPER_WS_SERVER = "ws://localhost:8011";
+
const BOARD_ICONS = {
PLAYER: "😀",
PLAYER_ON_DESTINATION: "😎",
@@ -13,10 +15,10 @@ function createBoard(board) {
colHtml += `
`;
}
html += `
-
- ${colHtml}
-
- `;
+
+ ${colHtml}
+
+ `;
}
document.getElementById("board-content").innerHTML = html;
}
@@ -33,10 +35,10 @@ function renderCellContent(position, content) {
}
function renderPlayerList(players) {
- const html = players
+ document.getElementById("players-content").innerHTML = players
.filter((player) => player.active)
.map((player) => {
- const onDestination = player.state == "ON_DESTINATION";
+ const onDestination = player.state === "ON_DESTINATION";
return `
${player.name} (${player.move_count})
@@ -45,7 +47,6 @@ function renderPlayerList(players) {
`;
})
.join("");
- document.getElementById("players-content").innerHTML = html;
}
function renderPlayers(players) {
@@ -53,14 +54,13 @@ function renderPlayers(players) {
.filter((player) => player.active)
.forEach((player) => {
const cell = findCell(player.position);
- const onDestination = player.state == "ON_DESTINATION";
+ const onDestination = player.state === "ON_DESTINATION";
const playerIcon = onDestination ? BOARD_ICONS.PLAYER_ON_DESTINATION : BOARD_ICONS.PLAYER;
if (cell) {
- const html = `
+ cell.innerHTML = `
${player.name}
${playerIcon}
`;
- cell.innerHTML = html;
}
});
}
@@ -100,7 +100,7 @@ function productPurchaseStart(products, purchaseTimeout) {
const contentElement = document.getElementById("products-content");
const purchaseTimeoutElement = document.getElementById("purchase-countdown");
- const html = products
+ contentElement.innerHTML = products
.map((product) => {
return `
@@ -112,8 +112,6 @@ function productPurchaseStart(products, purchaseTimeout) {
`;
})
.join("");
-
- contentElement.innerHTML = html;
containerElement.classList.remove("d-none");
purchaseTimeoutElement.innerText = purchaseTimeout;
}
@@ -134,7 +132,9 @@ function productPurchaseDone(product) {
}
function wsConnect() {
- let ws = new WebSocket("ws://localhost:8011");
+ console.log("Attempting to connect to", FAIRHOPPER_WS_SERVER);
+ let ws = new WebSocket(FAIRHOPPER_WS_SERVER);
+
ws.onopen = () => {
console.log("WS connected");
};
@@ -162,7 +162,7 @@ function wsConnect() {
};
ws.onclose = (e) => {
- setTimeout(function () {
+ setTimeout(() => {
wsConnect();
}, 1000);
};