duzo zmian, funkcji

This commit is contained in:
Mateusz Gruszczyński
2025-07-04 11:07:23 +02:00
parent 4e2bc0434f
commit 4de8a9cac1
8 changed files with 390 additions and 96 deletions

View File

@ -91,6 +91,24 @@ function setupList(listId, username) {
updateItemState(data.item_id, false);
});
socket.on('expense_added', data => {
// Osobne bo w html musi byc unikatowy a wyswietlam w dwoch miejscach
const badgeEl = document.getElementById('total-expense1');
if (badgeEl) {
badgeEl.innerHTML = `💸 ${data.total.toFixed(2)} PLN`;
badgeEl.classList.remove('bg-secondary');
badgeEl.classList.add('bg-success');
badgeEl.style.display = '';
}
const summaryEl = document.getElementById('total-expense2');
if (summaryEl) {
summaryEl.innerHTML = `<b>💸 Łącznie wydano:</b> ${data.total.toFixed(2)} PLN`;
}
showToast(`Dodano wydatek: ${data.amount.toFixed(2)} PLN`);
});
socket.on('item_added', data => {
showToast(`${data.added_by} dodał: ${data.name}`);
const li = document.createElement('li');
@ -226,6 +244,21 @@ function editItem(id, oldName) {
}
}
function submitExpense() {
const amountInput = document.getElementById('expenseAmount');
const amount = parseFloat(amountInput.value);
if (isNaN(amount) || amount <= 0) {
showToast('Podaj poprawną kwotę!');
return;
}
socket.emit('add_expense', {
list_id: LIST_ID,
amount: amount
});
amountInput.value = '';
}
function copyLink(link) {
if (navigator.share) {
navigator.share({