try to fix this spaghetti of a code

This commit is contained in:
Frederik Spirgi
2026-09-09 10:51:30 +02:00
parent b26155b49d
commit 2194ea4f0d
+7 -10
View File
@@ -38,7 +38,7 @@ document.addEventListener("DOMContentLoaded", () => {
let callAmount = 0; let callAmount = 0;
let countdownTimer = null; let countdownTimer = null;
const actionTooltips = { const actionTooltips = {
hit: "Check or call if your bet already matches the table.", hit: "Check when no chips are owed; otherwise call the table bet.",
fold: "Give up this hand and lose your current stake.", fold: "Give up this hand and lose your current stake.",
bet: "Open the bet dialog to add chips to the pot." bet: "Open the bet dialog to add chips to the pot."
}; };
@@ -131,6 +131,7 @@ document.addEventListener("DOMContentLoaded", () => {
finally { actionPending = false; updateActionButtons(); } finally { actionPending = false; updateActionButtons(); }
}; };
const closeModal = () => { const closeModal = () => {
if (betModal.classList.contains("hidden")) return;
betModal.classList.add("hidden"); betModal.classList.add("hidden");
previousFocus?.focus(); previousFocus?.focus();
}; };
@@ -286,7 +287,7 @@ document.addEventListener("DOMContentLoaded", () => {
button.addEventListener("click", () => { button.addEventListener("click", () => {
const action = button.dataset.action; const action = button.dataset.action;
if (isSpectator) { if (isSpectator) {
showError("You are out of chips and can only spectate."); showError("You are not active in this hand.");
return; return;
} }
if (!isYourTurn) { if (!isYourTurn) {
@@ -301,16 +302,12 @@ document.addEventListener("DOMContentLoaded", () => {
return; return;
} }
sendSocketMessage({type: "poker:action", action, payload: {lobbyId}}).catch(() => { sendSocketMessage({type: "poker:action", action}).catch(error => showError(error.message));
showError("Could not send poker action.");
});
}); });
}); });
leaveTable.addEventListener("click", () => { leaveTable.addEventListener("click", () => {
sendSocketMessage({type: "lobby:leave", lobbyId}).catch(() => { sendSocketMessage({type: "lobby:leave", lobbyId}).catch(error => showError(error.message));
showError("Could not leave table.");
});
}); });
closeBet.addEventListener("click", closeModal); closeBet.addEventListener("click", closeModal);
@@ -328,7 +325,7 @@ document.addEventListener("DOMContentLoaded", () => {
increaseBet.addEventListener("click", () => setBetValue(Number(betRange.value) + 10)); increaseBet.addEventListener("click", () => setBetValue(Number(betRange.value) + 10));
confirmBet.addEventListener("click", () => { confirmBet.addEventListener("click", () => {
if (isSpectator) { if (isSpectator) {
showError("You are out of chips and can only spectate."); showError("You are not active in this hand.");
betModal.classList.add("hidden"); betModal.classList.add("hidden");
return; return;
} }
@@ -341,7 +338,7 @@ document.addEventListener("DOMContentLoaded", () => {
type: "poker:action", type: "poker:action",
action: "bet", action: "bet",
payload: {amount: Number(betRange.value), lobbyId} payload: {amount: Number(betRange.value), lobbyId}
}).catch(() => showError("Could not place bet.")); }).catch(error => showError(error.message));
closeModal(); closeModal();
}); });
}); });