This commit is contained in:
2026-03-05 22:38:31 +02:00
parent e520ff8bc5
commit e879703041
9 changed files with 106 additions and 112 deletions

View File

@@ -1,5 +1,4 @@
const USERNAME_KEY = 'scrumPoker.username';
const CARD_ICONS = ['★', '◆', '✦', '☀', '☘', '⚙', '♣', '♠', '♥', '♦', '✚', '⚡', '☾', '✿'];
const roomID = document.body.dataset.roomId;
const params = new URLSearchParams(window.location.search);
@@ -37,6 +36,10 @@ const savedUsername = localStorage.getItem(USERNAME_KEY) || '';
joinUsernameInput.value = savedUsername;
joinAdminTokenInput.value = adminToken;
if (!window.CardUI || typeof window.CardUI.appendFace !== 'function') {
throw new Error('CardUI is not loaded. Ensure /static/js/cards.js is included before room.js.');
}
function setJoinError(message) {
if (!message) {
@@ -100,7 +103,8 @@ async function joinRoom({ username, role, password, participantIdOverride }) {
function renderParticipants(participants, isRevealed) {
participantList.innerHTML = '';
participants.forEach((participant) => {
const visibleParticipants = participants.filter((participant) => participant.connected);
visibleParticipants.forEach((participant) => {
const item = document.createElement('li');
item.className = 'participant-item';
@@ -138,41 +142,15 @@ function parseNumericVote(value) {
return Number(value);
}
function iconForCard(value) {
if (value === '?') return '❓';
if (value === '☕') return '☕';
if (value === '∞') return '∞';
let hash = 0;
for (let i = 0; i < value.length; i += 1) {
hash = (hash * 31 + value.charCodeAt(i)) >>> 0;
}
return CARD_ICONS[hash % CARD_ICONS.length];
}
function appendCardFace(el, value) {
const topLeft = document.createElement('span');
topLeft.className = 'card-corner top-left';
topLeft.textContent = value;
const center = document.createElement('span');
center.className = 'card-center-icon';
center.textContent = iconForCard(value);
const bottomRight = document.createElement('span');
bottomRight.className = 'card-corner bottom-right';
bottomRight.textContent = value;
el.appendChild(topLeft);
el.appendChild(center);
el.appendChild(bottomRight);
}
function calculateSummary(state) {
const rows = new Map();
const numericVotes = [];
state.participants.forEach((participant) => {
if (!participant.connected) {
return;
}
if (participant.role !== 'participant' || !participant.hasVoted || !participant.voteValue) {
return;
}
@@ -242,7 +220,7 @@ function renderSummary(state) {
}
function renderCards(cards, participants, isRevealed) {
const self = participants.find((participant) => participant.id === participantID);
const self = participants.find((participant) => participant.id === participantID && participant.connected);
const canVote = self && self.role === 'participant';
const selfVote = self ? self.voteValue : '';
@@ -253,7 +231,7 @@ function renderCards(cards, participants, isRevealed) {
card.type = 'button';
card.className = 'vote-card';
card.setAttribute('aria-label', `Vote ${value}`);
appendCardFace(card, value);
window.CardUI.appendFace(card, value);
if (selfVote === value && !isRevealed) {
card.classList.add('is-selected');
@@ -289,8 +267,8 @@ function renderState(state) {
adminControls.classList.add('hidden');
}
const votedCount = state.participants.filter((p) => p.role === 'participant' && p.hasVoted).length;
const totalParticipants = state.participants.filter((p) => p.role === 'participant').length;
const votedCount = state.participants.filter((p) => p.connected && p.role === 'participant' && p.hasVoted).length;
const totalParticipants = state.participants.filter((p) => p.connected && p.role === 'participant').length;
roomStatus.textContent = `Votes: ${votedCount}/${totalParticipants}`;
}