Skip to content

Commit dacb6ce

Browse files
author
Basu Jindal
committed
add likes
1 parent bf81894 commit dacb6ce

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

css/thoughts.css

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,20 @@
540540
}
541541

542542
.comment-submit {
543-
padding: 0.5rem 1rem;
544-
background: var(--accent);
545-
color: white;
546-
border: none;
543+
padding: 0.5rem 1.25rem;
544+
background: transparent;
545+
color: var(--text);
546+
border: 2px solid var(--accent);
547547
border-radius: 20px;
548-
font-size: 0.85rem;
548+
font-size: 0.9rem;
549549
font-weight: 500;
550550
cursor: pointer;
551-
transition: background 0.2s;
551+
transition: background 0.2s, transform 0.2s, color 0.2s;
552552
}
553553

554554
.comment-submit:hover {
555-
background: var(--accent-hover);
555+
background: var(--code-bg);
556+
color: var(--text);
556557
}
557558

558559
/* Comment input avatar */

js/thoughts.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,20 @@
690690
if (!response.ok) {
691691
throw new Error('Failed to like post');
692692
}
693+
694+
// Update local posts array with server response
695+
const data = await response.json();
696+
const post = posts.find(p => p.id == postId);
697+
if (post) {
698+
post.likes = data.likes;
699+
post.user_liked = data.user_liked;
700+
}
701+
702+
// Update UI with actual server values
703+
countSpan.textContent = data.likes > 0 ? data.likes : '';
704+
btn.classList.toggle('liked', data.user_liked);
705+
svg.setAttribute('fill', data.user_liked ? 'currentColor' : 'none');
706+
693707
} catch (error) {
694708
// Revert on error
695709
console.error('Error liking post:', error);

thoughts-api

0 commit comments

Comments
 (0)