-
-
-
+
${mediaHtml}
-
-
${esc(entry.name)}
+
+ ${esc(entry.name)}
-
${esc(formatQty(entry.addedAmount))} ${esc(unitLabel(entry.unit))}
+
${esc(formatQty(entry.addedAmount))} ${esc(unitLabel(entry.unit))}
`;
}
@@ -516,14 +544,15 @@ function undoBoughtEntry(entryId) {
/* ══════════════════════ RENDERING ══════════════════════ */
-function renderProgress(activeItems, sessionLog) {
- const touchedIds = new Set(sessionLog.map((e) => e.ingredientId));
- const bought = touchedIds.size;
- const untouched = activeItems.filter((i) => !touchedIds.has(i.ingredientId)).length;
- const total = bought + untouched;
-
- const barEl = document.getElementById('sl-progress-bar');
- if (barEl) barEl.style.width = total > 0 ? `${Math.round((bought / total) * 100)}%` : '0%';
+function renderBoughtBadge(count) {
+ const badge = document.getElementById('sl-bought-badge');
+ if (!badge) return;
+ if (count > 0) {
+ badge.textContent = String(count);
+ badge.style.display = 'flex';
+ } else {
+ badge.style.display = 'none';
+ }
}
function renderBoard() {
@@ -576,22 +605,17 @@ function renderBoard() {
function renderBought() {
const sessionLog = getSessionLog();
- const section = document.getElementById('sl-bought-section');
- const countEl = document.getElementById('sl-bought-count');
+ const countEl = document.getElementById('sl-bought-popup-count');
const list = document.getElementById('sl-bought-list');
- if (!section || !list || !countEl) return;
+ if (!list || !countEl) return;
- if (sessionLog.length === 0) { section.classList.add('hidden'); return; }
-
- section.classList.remove('hidden');
countEl.textContent = String(sessionLog.length);
- const chevron = document.getElementById('sl-bought-chevron');
- if (chevron) chevron.style.transform = boughtSectionOpen ? 'rotate(90deg)' : '';
+ if (sessionLog.length === 0) {
+ list.innerHTML = `
Brak kupionych
`;
+ return;
+ }
- if (!boughtSectionOpen) { list.classList.add('hidden'); return; }
-
- list.classList.remove('hidden');
list.innerHTML = [...sessionLog].reverse().map((e) => boughtItemHtml(e)).join('');
list.querySelectorAll('.sl-swipe-wrap').forEach((wrap) => {
const entryId = wrap.querySelector('.sl-swipe-inner')?.dataset.entryId;
@@ -601,9 +625,8 @@ function renderBought() {
}
function renderAll() {
- const activeItems = computeActiveItems();
const sessionLog = getSessionLog();
- renderProgress(activeItems, sessionLog);
+ renderBoughtBadge(sessionLog.length);
renderBoard();
renderBought();
}
@@ -663,12 +686,25 @@ export function setupShoppingList() {
toggleCalendar();
});
+ document.getElementById('sl-bought-btn')?.addEventListener('click', (e) => {
+ e.stopPropagation();
+ toggleBoughtPopup();
+ });
+
document.addEventListener('click', (e) => {
- if (!calendarOpen) return;
- const popup = document.getElementById('sl-calendar-popup');
- const pill = document.getElementById('sl-range-pill');
- if (popup && !popup.contains(e.target) && pill && !pill.contains(e.target)) {
- closeCalendar();
+ if (calendarOpen) {
+ const popup = document.getElementById('sl-calendar-popup');
+ const pill = document.getElementById('sl-range-pill');
+ if (popup && !popup.contains(e.target) && pill && !pill.contains(e.target)) {
+ closeCalendar();
+ }
+ }
+ if (boughtPopupOpen) {
+ const popup = document.getElementById('sl-bought-popup');
+ const btn = document.getElementById('sl-bought-btn');
+ if (popup && !popup.contains(e.target) && btn && !btn.contains(e.target)) {
+ closeBoughtPopup();
+ }
}
});
@@ -685,15 +721,11 @@ export function setupShoppingList() {
});
- document.getElementById('sl-clear-session')?.addEventListener('click', () => {
+ document.getElementById('sl-clear-session')?.addEventListener('click', (e) => {
+ e.stopPropagation();
clearSessionLog();
renderAll();
});
- document.getElementById('sl-bought-toggle')?.addEventListener('click', () => {
- boughtSectionOpen = !boughtSectionOpen;
- renderBought();
- });
-
window.refreshShoppingList = refreshShoppingList;
}