diff --git a/static/js/functions.js b/static/js/functions.js index 9c39b67..45f6811 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -19,7 +19,7 @@ function updateItemState(itemId, isChecked) { applyHidePurchased(); } -function updateProgressBar() { +/* function updateProgressBar() { const items = document.querySelectorAll('#items li'); const total = items.length; const purchased = Array.from(items).filter(li => li.classList.contains('bg-success')).length; @@ -31,6 +31,48 @@ function updateProgressBar() { progressBar.setAttribute('aria-valuenow', percent); progressBar.textContent = `${percent}%`; } +} */ + +function updateProgressBar() { + const items = document.querySelectorAll('#items li'); + const total = items.length; + const purchased = Array.from(items).filter(li => li.classList.contains('bg-success')).length; + const percent = total > 0 ? Math.round((purchased / total) * 100) : 0; + + // Pasek postępu + const progressBar = document.getElementById('progress-bar'); + if (progressBar) { + progressBar.style.width = `${percent}%`; + progressBar.setAttribute('aria-valuenow', percent); + progressBar.textContent = percent > 0 ? `${percent}%` : ''; // opcjonalnie + } + + // Label na pasku postępu + const progressLabel = document.getElementById('progress-label'); + if (progressLabel) { + progressLabel.textContent = `${percent}%`; + if (percent === 0) { + progressLabel.style.display = 'inline'; + } else { + progressLabel.style.display = 'none'; + } + // Kolor tekstu labela + if (percent < 50) { + progressLabel.classList.remove('text-dark'); + progressLabel.classList.add('text-white'); + } else { + progressLabel.classList.remove('text-white'); + progressLabel.classList.add('text-dark'); + } + } + + // Nagłówek + const purchasedCount = document.getElementById('purchased-count'); + if (purchasedCount) purchasedCount.textContent = purchased; + const totalCount = document.getElementById('total-count'); + if (totalCount) totalCount.textContent = total; + const percentValue = document.getElementById('percent-value'); + if (percentValue) percentValue.textContent = percent; } function addItem(listId) { @@ -92,16 +134,14 @@ function submitExpense(listId) { } function copyLink(link) { - // Najpierw sprawdź Web Share API (działa na większości urządzeń mobilnych) if (navigator.share) { navigator.share({ title: 'Udostępnij link', - text: 'Sprawdź ten link:', + text: 'Link do listy::', url: link }).then(() => { showToast('Link udostępniony!'); }).catch((err) => { - // Użytkownik anulował lub wystąpił błąd – próbujemy dalej tryClipboard(link); }); return; diff --git a/templates/list.html b/templates/list.html index 7c95566..3562ab7 100644 --- a/templates/list.html +++ b/templates/list.html @@ -50,11 +50,13 @@ Lista: {{ list.title }}