From eaa5fde7a555afe1395ed5b1f68fbe7886fa671f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 11 Jul 2025 23:47:59 +0200 Subject: [PATCH] =?UTF-8?q?Funkcja:=20suwak=20z=20ukryciem=20zaznaczonych?= =?UTF-8?q?=20prodkt=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/css/style.css | 14 ++++++++ static/js/functions.js | 68 ++++++++++++++++++++++++++++----------- templates/list.html | 5 +++ templates/list_share.html | 8 +++++ 4 files changed, 76 insertions(+), 19 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index fb1088c..67f9cae 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -264,4 +264,18 @@ input.form-control { #empty-placeholder { font-style: italic; pointer-events: none; +} + +#items li.hide-purchased { + display: none !important; +} + +.list-group-item:first-child, +.list-group-item:last-child { + border-radius: 0 !important; +} + +.fade-out { + opacity: 0; + transition: opacity 0.5s ease; } \ No newline at end of file diff --git a/static/js/functions.js b/static/js/functions.js index 0bd07a3..1ec3dd0 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -16,6 +16,7 @@ function updateItemState(itemId, isChecked) { if (sp) sp.remove(); } updateProgressBar(); + applyHidePurchased(); } function updateProgressBar() { @@ -103,28 +104,43 @@ function copyLink(link) { } } -/* function shareLink(link) { - if (navigator.share) { - navigator.share({ - title: 'Udostępnij moją listę', - text: 'Zobacz tę listę!', - url: link - }) - .catch((error) => { - console.error('Błąd podczas udostępniania', error); - alert('Nie udało się udostępnić linka'); - }); - } else { - copyLink(link); - } -} +function applyHidePurchased(isInit = false) { + console.log("applyHidePurchased: wywołana, isInit =", isInit); + const toggle = document.getElementById('hidePurchasedToggle'); + if (!toggle) return; + const hide = toggle.checked; -function fallbackCopy(link) { - navigator.clipboard.writeText(link).then(() => { - alert('Link skopiowany do schowka!'); + const items = document.querySelectorAll('#items li'); + + items.forEach(li => { + const isPurchased = li.classList.contains('bg-success'); + + if (isPurchased) { + if (hide) { + if (isInit) { + // Jeśli inicjalizacja: od razu ukryj + li.classList.add('hide-purchased'); + li.classList.remove('fade-out'); + } else { + // Z animacją + li.classList.add('fade-out'); + setTimeout(() => { + li.classList.add('hide-purchased'); + }, 700); + } + } else { + // Odsłanianie + li.classList.remove('hide-purchased'); + setTimeout(() => { + li.classList.remove('fade-out'); + }, 10); + } + } else { + // Element niekupiony — zawsze pokazany + li.classList.remove('hide-purchased', 'fade-out'); + } }); } - */ function openList(link) { window.open(link, '_blank'); @@ -282,6 +298,7 @@ function updateListSmoothly(newItems) { updateProgressBar(); toggleEmptyPlaceholder(); + applyHidePurchased(); } document.addEventListener("DOMContentLoaded", function() { @@ -302,3 +319,16 @@ document.addEventListener("DOMContentLoaded", function() { localStorage.setItem("receiptSectionOpen", "false"); }); }); + +document.addEventListener("DOMContentLoaded", function() { + const toggle = document.getElementById('hidePurchasedToggle'); + if (!toggle) return; + + const savedState = localStorage.getItem('hidePurchasedToggle'); + toggle.checked = savedState === 'true'; + applyHidePurchased(true); + toggle.addEventListener('change', function() { + localStorage.setItem('hidePurchasedToggle', toggle.checked ? 'true' : 'false'); + applyHidePurchased(); + }); +}); \ No newline at end of file diff --git a/templates/list.html b/templates/list.html index d3a62e6..66fd81b 100644 --- a/templates/list.html +++ b/templates/list.html @@ -78,6 +78,11 @@ Lista: {{ list.title }} {% endif %} +
+ + +
+