Новые изменения в компонентах
This commit is contained in:
parent
5bb4525f63
commit
d4394a7597
5 changed files with 145 additions and 34 deletions
|
|
@ -46,7 +46,7 @@ const gradientColors = {
|
|||
};
|
||||
---
|
||||
|
||||
<article class="review-card animate-on-scroll" data-animation="fade-up" data-review-id={reviewId}>
|
||||
<article class="review-card animate-on-scroll" data-animation="fade-up" data-review-id={reviewId} data-initial-likes={initialLikes}>
|
||||
<!-- Декоративный элемент -->
|
||||
<div class="card-decoration"></div>
|
||||
|
||||
|
|
@ -480,10 +480,11 @@ const gradientColors = {
|
|||
|
||||
document.querySelectorAll('.review-card').forEach((card) => {
|
||||
const reviewId = (card as HTMLElement).dataset.reviewId;
|
||||
const initialLikes = parseInt((card as HTMLElement).dataset.initialLikes || '0', 10);
|
||||
const likeBtn = card.querySelector('[data-vote="likes"]') as HTMLButtonElement;
|
||||
const likesCount = card.querySelector('[data-likes-count]');
|
||||
|
||||
console.log('[ReviewCard] reviewId:', reviewId, 'likeBtn:', likeBtn, 'likesCount:', likesCount);
|
||||
console.log('[ReviewCard] reviewId:', reviewId, 'likeBtn:', likeBtn, 'likesCount:', likesCount, 'initialLikes:', initialLikes);
|
||||
|
||||
if (!reviewId) {
|
||||
console.error('[ReviewCard] No reviewId found!');
|
||||
|
|
@ -492,12 +493,6 @@ const gradientColors = {
|
|||
|
||||
async function loadVotes() {
|
||||
console.log('[ReviewCard] Loading votes for:', reviewId);
|
||||
if (!pb.authStore.isValid) {
|
||||
console.log('[ReviewCard] Not logged in, keeping initialLikes:', initialLikes);
|
||||
if (likesCount) likesCount.textContent = initialLikes.toString();
|
||||
likeBtn?.classList.remove('active');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(`/api/reviews/vote?review_id=${reviewId}`, {
|
||||
credentials: 'include',
|
||||
|
|
@ -507,12 +502,17 @@ const gradientColors = {
|
|||
const data = await response.json();
|
||||
console.log('[ReviewCard] Votes data:', data);
|
||||
if (likesCount) likesCount.textContent = data.likes.toString();
|
||||
if (data.userVote === 'likes') {
|
||||
if (data.userVote === 'likes' && pb.authStore.isValid) {
|
||||
likeBtn?.classList.add('active');
|
||||
} else {
|
||||
likeBtn?.classList.remove('active');
|
||||
}
|
||||
} else {
|
||||
if (likesCount) likesCount.textContent = initialLikes.toString();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[ReviewCard] Error loading votes:', e);
|
||||
if (likesCount) likesCount.textContent = initialLikes.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue