File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments