Reorganise the views and prepare summary
All checks were successful
Build and Deploy / build-and-push (push) Successful in 23s

This commit is contained in:
2026-03-26 22:29:06 +01:00
parent d9cf61ee74
commit f80b115cae
12 changed files with 1394 additions and 484 deletions

View File

@@ -1,7 +1,9 @@
import {
addFreeformLine,
addFreeformList,
applyCheckedKitchenListToPantry,
categoryLabel,
clearCheckedInList,
deleteList,
getActiveList,
getListSummaries,
@@ -9,6 +11,7 @@ import {
removeItemFromList,
setActiveListId,
toggleItemInList,
updateKitchenItemAmount,
} from '../services/pantryShopping.js';
import { showAppToast } from '../ui/toast.js';
@@ -34,6 +37,14 @@ export function getShoppingHTML() {
<button type="button" id="shopping-delete-list" class="hidden w-full py-2 rounded-lg text-xs font-medium text-red-600 hover:bg-red-50 transition-colors">
Usuń tę listę (nie dotyczy listy kuchennej)
</button>
<div id="shopping-kitchen-actions" class="hidden flex gap-2">
<button type="button" id="shopping-to-pantry" class="flex-1 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-semibold transition-colors flex items-center justify-center gap-1.5">
<i class="fas fa-warehouse text-[10px]"></i> Kupione → spiżarnia
</button>
<button type="button" id="shopping-clear-checked" class="flex-1 py-2.5 rounded-xl border border-gray-200 bg-white text-gray-700 hover:bg-gray-50 text-xs font-semibold transition-colors flex items-center justify-center gap-1.5">
<i class="fas fa-broom text-[10px]"></i> Wyczyść kupione
</button>
</div>
</div>
<div id="shopping-freeform-add" class="hidden shrink-0 px-4 pt-3 pb-2 space-y-2 border-b border-gray-100">
@@ -68,11 +79,14 @@ function syncChromeForList() {
const isKitchen = list.type === 'kitchen';
const delBtn = document.getElementById('shopping-delete-list');
const ffAdd = document.getElementById('shopping-freeform-add');
const kitchenActions = document.getElementById('shopping-kitchen-actions');
if (ffAdd) ffAdd.classList.toggle('hidden', isKitchen);
if (delBtn) delBtn.classList.toggle('hidden', isKitchen);
if (delBtn) {
delBtn.classList.toggle('hidden', isKitchen);
if (kitchenActions) {
const hasChecked = isKitchen && list.items.some((i) => i.checked);
kitchenActions.classList.toggle('hidden', !hasChecked);
}
}
@@ -109,7 +123,7 @@ function renderKitchenItems() {
</button>
<div class="min-w-0 flex-1">
<p class="text-sm font-medium text-gray-900 ${it.checked ? 'line-through text-gray-500' : ''}">${escapeHtml(it.name)}</p>
<p class="text-xs text-gray-600 tabular-nums mt-0.5">${escapeHtml(String(it.amount))} ${escapeHtml(it.unit)}</p>
<button type="button" data-shop-edit-amount="${escapeHtml(it.id)}" data-current-amount="${it.amount}" data-unit="${escapeHtml(it.unit)}" class="text-xs text-gray-600 tabular-nums mt-0.5 hover:text-gray-900 underline decoration-dashed underline-offset-2 cursor-pointer">${escapeHtml(String(it.amount))} ${escapeHtml(it.unit)}</button>
${it.sourceNote ? `<p class="text-[10px] text-gray-400 mt-1">${escapeHtml(it.sourceNote)}</p>` : ''}
</div>
<button type="button" data-shop-remove="${escapeHtml(it.id)}" class="shrink-0 w-8 h-8 rounded-full text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors" aria-label="Usuń">
@@ -177,6 +191,23 @@ function bindItemButtons(listId) {
refreshShopping();
});
});
root.querySelectorAll('[data-shop-edit-amount]').forEach((btn) => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
const itemId = btn.getAttribute('data-shop-edit-amount');
const current = btn.getAttribute('data-current-amount');
const unit = btn.getAttribute('data-unit');
const newVal = window.prompt(`Nowa ilość (${unit}):`, current);
if (newVal === null) return;
const num = parseFloat(newVal.replace(',', '.'));
if (!Number.isFinite(num) || num < 0) {
showAppToast('Nieprawidłowa wartość.');
return;
}
updateKitchenItemAmount(listId, itemId, num);
refreshShopping();
});
});
}
export function refreshShopping() {
@@ -232,6 +263,28 @@ export function setupShopping() {
}
});
document.getElementById('shopping-to-pantry')?.addEventListener('click', () => {
const list = getActiveList();
if (list.type !== 'kitchen') return;
const checked = list.items.filter((i) => i.checked);
if (checked.length === 0) return;
const preview = checked.map((i) => `${i.name}: ${i.amount} ${i.unit}`).join('\n');
if (!window.confirm(`Przenieść do spiżarni?\n\n${preview}`)) return;
applyCheckedKitchenListToPantry();
showAppToast(`Przeniesiono ${checked.length} pozycji do spiżarni.`);
window.refreshPantry?.();
refreshShopping();
});
document.getElementById('shopping-clear-checked')?.addEventListener('click', () => {
const list = getActiveList();
const checkedCount = list.items.filter((i) => i.checked).length;
if (checkedCount === 0) return;
clearCheckedInList(list.id);
showAppToast(`Usunięto ${checkedCount} kupionych pozycji.`);
refreshShopping();
});
refreshShopping();
window.refreshShopping = refreshShopping;
}