вроде почти все
осталось вывод категорий и состояний
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// components/likes/view.js
|
||||
export class LikesView {
|
||||
constructor() {
|
||||
this.likesContainer = document.getElementById('likesContainer');
|
||||
this.emptyLikesElement = document.querySelector('.empty-likes');
|
||||
}
|
||||
|
||||
showLikes(items) {
|
||||
if (!this.likesContainer) return;
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
this.showEmptyLikes();
|
||||
return;
|
||||
}
|
||||
|
||||
// 👉 Если товары есть — убираем блок "пусто"
|
||||
this.hideEmptyLikes();
|
||||
|
||||
const likesHTML = items.map(item => this.createLikesItemHTML(item)).join('');
|
||||
|
||||
// 👉 Добавляем заголовок "Избранное"
|
||||
this.likesContainer.innerHTML = `
|
||||
<h2 class="mb-4 text-center">Избранное</h2>
|
||||
<div class="row g-3">${likesHTML}</div>
|
||||
`;
|
||||
}
|
||||
|
||||
createLikesItemHTML(item) {
|
||||
return `
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100 border-0 shadow like-item" data-id="${item.id}">
|
||||
<img src="${item.image}" class="card-img-top" alt="${item.name}">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${item.name}</h5>
|
||||
<p class="card-text">${item.description}</p>
|
||||
<span class="fw-bold text-muted">$${item.price}</span>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent d-flex justify-content-between">
|
||||
<button class="btn btn-sm btn-outline-danger remove-like-btn">
|
||||
<i class="bi bi-trash"></i> Удалить
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-primary move-to-basket-btn">
|
||||
<i class="bi bi-cart-plus"></i> В корзину
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
showEmptyLikes() {
|
||||
if (this.emptyLikesElement) {
|
||||
this.emptyLikesElement.style.display = 'block';
|
||||
}
|
||||
if (this.likesContainer) {
|
||||
this.likesContainer.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
hideEmptyLikes() {
|
||||
if (this.emptyLikesElement) {
|
||||
this.emptyLikesElement.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
showNotification(message, type = 'success') {
|
||||
const notification = document.createElement('div');
|
||||
notification.className = `alert alert-${type === 'success' ? 'success' : 'danger'} alert-dismissible fade show`;
|
||||
notification.style.cssText = 'position: fixed; top: 20px; right: 20px; z-index: 1050; min-width: 300px;';
|
||||
notification.innerHTML = `
|
||||
${message}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
`;
|
||||
document.body.appendChild(notification);
|
||||
setTimeout(() => {
|
||||
if (notification.parentNode) notification.remove();
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user