Skip to content

Commit d808607

Browse files
committed
don't reload the page when following/unfollowing comments on posts if JS is enabled
1 parent bf81a43 commit d808607

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

app/assets/javascripts/comments.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,35 @@ $(() => {
339339
$tgt.find('.js-text').text('copy link');
340340
}, 1000);
341341
});
342+
343+
QPixel.DOM.addSelectorListener('click', '.js-follow-comments', async (ev) => {
344+
ev.preventDefault();
345+
346+
const { target } = ev;
347+
348+
if (!QPixel.DOM.isHTMLElement(target)) {
349+
return;
350+
}
351+
352+
const { postId, action } = target.dataset;
353+
354+
if (!postId || !action) {
355+
return;
356+
}
357+
358+
const data = await QPixel.followComments(postId);
359+
360+
QPixel.handleJSONResponse(data, () => {
361+
const isFollowing = action === 'follow';
362+
363+
target.dataset.action = isFollowing ? 'unfollow' : 'follow';
364+
365+
const icon = document.createElement('i');
366+
icon.classList.add('fas', 'fa-fw', isFollowing ? 'fa-bell-slash' : 'fa-bell');
367+
368+
const text = document.createTextNode(` ${ isFollowing ? 'Unfollow' : 'Follow' } new`);
369+
370+
target.replaceChildren(icon, text);
371+
});
372+
});
342373
});

0 commit comments

Comments
 (0)