duzo poprawek ux i logicznych

This commit is contained in:
Mateusz Gruszczyński
2025-07-28 00:04:12 +02:00
parent a5025b94ff
commit b9b91ff82b
7 changed files with 68 additions and 44 deletions

View File

@@ -281,6 +281,9 @@ function renderItem(item, isShare = window.IS_SHARE, showEditOnly = false) {
: 'item-not-checked'
}`;
const isOwner = window.IS_OWNER === true || window.IS_OWNER === 'true';
const allowEdit = !isShare || showEditOnly || isOwner;
let quantityBadge = '';
if (item.quantity && item.quantity > 1) {
quantityBadge = `<span class="badge bg-secondary">x${item.quantity}</span>`;
@@ -309,8 +312,8 @@ function renderItem(item, isShare = window.IS_SHARE, showEditOnly = false) {
let rightButtons = '';
// ✏️ i 🗑️ — tylko jeśli nie jesteśmy w trybie /share lub jesteśmy w 15s (tymczasowo)
if (!isShare || showEditOnly) {
// ✏️ i 🗑️ — tylko jeśli nie jesteśmy w trybie /share lub jesteśmy w 15s (tymczasowo) lub jesteśmy właścicielem
if (allowEdit) {
rightButtons += `
<button type="button" class="btn btn-outline-light"
onclick="editItem(${item.id}, '${item.name.replace(/'/g, "\\'")}', ${item.quantity || 1})">
@@ -332,7 +335,8 @@ function renderItem(item, isShare = window.IS_SHARE, showEditOnly = false) {
}
// ⚠️ tylko jeśli NIE jest oznaczony jako niekupiony i nie jesteśmy w 15s
if (!item.not_purchased && !showEditOnly) {
if (!item.not_purchased && (isOwner || (isShare && !showEditOnly))) {
rightButtons += `
<button type="button" class="btn btn-outline-light"
onclick="markNotPurchasedModal(event, ${item.id})">
@@ -341,7 +345,8 @@ function renderItem(item, isShare = window.IS_SHARE, showEditOnly = false) {
}
// 📝 tylko jeśli jesteśmy w /share i nie jesteśmy w 15s
if (isShare && !showEditOnly) {
if (isShare && !showEditOnly && !isOwner) {
rightButtons += `
<button type="button" class="btn btn-outline-light"
onclick="openNoteModal(event, ${item.id})">
@@ -349,7 +354,6 @@ function renderItem(item, isShare = window.IS_SHARE, showEditOnly = false) {
</button>`;
}
li.innerHTML = `${left}<div class="btn-group btn-group-sm" role="group">${rightButtons}</div>`;
if (item.added_by && item.owner_id && item.added_by_id && item.added_by_id !== item.owner_id) {

View File

@@ -205,43 +205,39 @@ function setupList(listId, username) {
});
socket.on('note_updated', data => {
const itemEl = document.getElementById(`item-${data.item_id}`);
if (itemEl) {
let noteEl = itemEl.querySelector('small');
if (noteEl) {
//noteEl.innerHTML = `[ Notatka: <b>${data.note}</b> ]`;
noteEl.innerHTML = `[ <b>${data.note}</b> ]`;
} else {
const newNote = document.createElement('small');
newNote.className = 'text-danger ms-4';
//newNote.innerHTML = `[ Notatka: <b>${data.note}</b> ]`;
newNote.innerHTML = `[ <b>${data.note}</b> ]`;
const idx = window.currentItems.findIndex(i => i.id === data.item_id);
if (idx !== -1) {
window.currentItems[idx].note = data.note;
const flexColumn = itemEl.querySelector('.d-flex.flex-column');
if (flexColumn) {
flexColumn.appendChild(newNote);
} else {
itemEl.appendChild(newNote);
}
const newItem = renderItem(window.currentItems[idx], true);
const oldItem = document.getElementById(`item-${data.item_id}`);
if (oldItem && newItem) {
oldItem.replaceWith(newItem);
}
}
showToast('Notatka dodana/zaktualizowana', 'success');
});
socket.on('item_edited', data => {
const nameSpan = document.getElementById(`name-${data.item_id}`);
if (nameSpan) {
let quantityBadge = '';
if (data.new_quantity && data.new_quantity > 1) {
quantityBadge = ` <span class="badge bg-secondary">x${data.new_quantity}</span>`;
}
nameSpan.innerHTML = `${data.new_name}${quantityBadge}`;
}
showToast(`Zaktualizowano produkt: ${data.new_name} (x${data.new_quantity})`, 'success');
});
updateProgressBar();
toggleEmptyPlaceholder();
socket.on('item_edited', data => {
const idx = window.currentItems.findIndex(i => i.id === data.item_id);
if (idx !== -1) {
window.currentItems[idx].name = data.new_name;
window.currentItems[idx].quantity = data.new_quantity;
const newItem = renderItem(window.currentItems[idx], true);
const oldItem = document.getElementById(`item-${data.item_id}`);
if (oldItem && newItem) {
oldItem.replaceWith(newItem);
}
}
showToast(`Zaktualizowano produkt: ${data.new_name} (x${data.new_quantity})`, 'success');
updateProgressBar();
toggleEmptyPlaceholder();
});
// --- WAŻNE: zapisz dane do reconnect ---
window.LIST_ID = listId;

View File

@@ -16,3 +16,24 @@ document.addEventListener("DOMContentLoaded", function () {
localStorage.setItem("receiptSectionOpen", "false");
});
});
document.addEventListener("DOMContentLoaded", function () {
const btn = document.getElementById("toggleReceiptBtn");
const target = document.querySelector(btn.getAttribute("data-bs-target"));
function updateUI() {
const isShown = target.classList.contains("show");
btn.innerHTML = isShown
? "📄 Ukryj sekcję paragonów"
: "📄 Pokaż sekcję paragonów";
btn.classList.toggle("active", isShown);
btn.classList.toggle("btn-outline-light", !isShown);
btn.classList.toggle("btn-secondary", isShown);
}
target.addEventListener("shown.bs.collapse", updateUI);
target.addEventListener("hidden.bs.collapse", updateUI);
updateUI();
});