From da01bda9bcedaf3dec9bdc6b53f929952061db8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Wed, 6 Aug 2025 22:15:59 +0200 Subject: [PATCH] fix w js --- static/js/functions.js | 18 ++++++++++++------ static/js/live.js | 5 ++++- static/js/notes.js | 13 +++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/static/js/functions.js b/static/js/functions.js index c228eb5..ee88791 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -20,6 +20,15 @@ function updateItemState(itemId, isChecked) { } function updateProgressBar() { + const barPurchased = document.getElementById('progress-bar-purchased'); + const barNotPurchased = document.getElementById('progress-bar-not-purchased'); + const barRemaining = document.getElementById('progress-bar-remaining'); + const progressLabel = document.getElementById('progress-label'); + + if (!barPurchased || !barNotPurchased || !barRemaining || !progressLabel) { + return; + } + const items = document.querySelectorAll('#items li'); const total = items.length; @@ -31,18 +40,15 @@ function updateProgressBar() { const percentNotPurchased = total > 0 ? (notPurchased / total) * 100 : 0; const percentRemaining = total > 0 ? (remaining / total) * 100 : 0; - document.getElementById('progress-bar-purchased').style.width = `${percentPurchased}%`; - document.getElementById('progress-bar-not-purchased').style.width = `${percentNotPurchased}%`; - document.getElementById('progress-bar-remaining').style.width = `${percentRemaining}%`; + barPurchased.style.width = `${percentPurchased}%`; + barNotPurchased.style.width = `${percentNotPurchased}%`; + barRemaining.style.width = `${percentRemaining}%`; - // etykieta - const progressLabel = document.getElementById('progress-label'); const percent = total > 0 ? Math.round((purchased / total) * 100) : 0; progressLabel.textContent = `${percent}%`; progressLabel.classList.toggle('text-white', percent < 51); progressLabel.classList.toggle('text-dark', percent >= 51); - // liczniki document.getElementById('purchased-count').textContent = purchased; document.getElementById('total-count').textContent = total; document.getElementById('percent-value').textContent = percent; diff --git a/static/js/live.js b/static/js/live.js index dfbaf7c..2b43def 100644 --- a/static/js/live.js +++ b/static/js/live.js @@ -153,7 +153,10 @@ function setupList(listId, username) { countdownBtn.disabled = true; countdownBtn.textContent = '15s'; - li.querySelector('.btn-group')?.prepend(countdownBtn); + const btnGroup = li.querySelector('.btn-group'); + if (btnGroup) { + btnGroup.prepend(countdownBtn); + } let seconds = 15; const intervalId = setInterval(() => { diff --git a/static/js/notes.js b/static/js/notes.js index ed6a4c2..e1fc693 100644 --- a/static/js/notes.js +++ b/static/js/notes.js @@ -1,10 +1,12 @@ -let currentItemId = null; +window.currentItemId = window.currentItemId ?? null; window.openNoteModal = function (event, itemId) { event.stopPropagation(); - currentItemId = itemId; + window.currentItemId = itemId; const noteEl = document.querySelector(`#item-${itemId} small.text-danger`); - document.getElementById('noteText').value = noteEl ? noteEl.innerText.replace(/\[|\]|Powód:/g, "").trim() : ""; + document.getElementById('noteText').value = noteEl + ? noteEl.innerText.replace(/\[|\]|Powód:/g, "").trim() + : ""; const modal = new bootstrap.Modal(document.getElementById('noteModal')); modal.show(); }; @@ -13,11 +15,10 @@ function submitNote(e) { e.preventDefault(); const text = document.getElementById('noteText').value; - if (currentItemId !== null) { - socket.emit('update_note', { item_id: currentItemId, note: text }); + if (window.currentItemId !== null) { + socket.emit('update_note', { item_id: window.currentItemId, note: text }); const modal = bootstrap.Modal.getInstance(document.getElementById('noteModal')); modal.hide(); } } -