Skip to content

Commit 3b974bf

Browse files
committed
restored follow comment thread client-side functionality
1 parent bc6bacb commit 3b974bf

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

app/assets/javascripts/comments.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ $(() => {
225225
});
226226
});
227227

228+
$(document).on('click', '.js-follow-thread', async (ev) => {
229+
ev.preventDefault();
230+
231+
const $tgt = $(ev.target);
232+
const threadID = $tgt.data("thread");
233+
234+
const data = await QPixel.followThread(threadID);
235+
236+
QPixel.handleJSONResponse(data, () => {
237+
const wrapper = getCommentThreadWrapper($tgt);
238+
openThread(wrapper, threadID);
239+
});
240+
});
241+
228242
$(document).on('click', '.js-lock-thread', async (ev) => {
229243
ev.preventDefault();
230244

app/assets/javascripts/qpixel_api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ window.QPixel = {
467467
return QPixel.parseJSONResponse(resp, 'Failed to delete thread');
468468
},
469469

470+
followThread: async (id) => {
471+
const resp = await QPixel.fetchJSON(`/comments/thread/${id}/follow`, {}, {
472+
headers: { 'Accept': 'application/json' },
473+
});
474+
475+
return QPixel.parseJSONResponse(resp, 'Failed to follow thread');
476+
},
477+
470478
lockThread: async (id, duration) => {
471479
const resp = await QPixel.fetchJSON(`/comments/thread/${id}/lock`, {
472480
duration,

app/views/comments/_thread_follow_link.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
</a>
1919
<% else %>
2020
<a href="#"
21-
class="widget--header-link js--restrict-thread"
22-
data-action="follow"
21+
class="widget--header-link js-follow-thread"
2322
data-thread="<%= thread.id %>"
2423
title="Follow this thread to be notified of every response."
2524
role="button"

global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,13 @@ interface QPixel {
561561
*/
562562
deleteThread?: (id: string) => Promise<QPixelResponseJSON>
563563

564+
/**
565+
* Attempts to follow a comment thread
566+
* @param id id of the thread to follow
567+
* @returns result of the operation
568+
*/
569+
followThread?: (id: string) => Promise<QPixelResponseJSON>
570+
564571
/**
565572
* Attempts to start following comments on a given post
566573
* @param postId id of the post to follow comments on

0 commit comments

Comments
 (0)