Topic preview
-
Hi guys, the plugin to return the embeddable post works great. However, I noticed that there appears to be caching of the results somewhere in the pipeline. If I make a change to the post, its not reflected in the
posts.getPostSummaryByPid
call until after a restart. Is there a way to force retrieval of the refreshed post content? -
One more question, how are events bound to template elements? As an example, lets say I want to include the
post/upvote
orpost/downvote
components in a custom template, how would these links get bound to an action that ultimately calls the appropriate upvote/downvote method? -
It happens here https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/postTools.js#L124-L130. The module that handles upvoting is https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/votes.js. When a click is detected on the vote buttons this function is called https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/votes.js#L73.
So if you want the upvoting on a different template you need to add the click handlers and call
votes.toggleVote
and pass the correct parameters like we do. -
@baris Thank you, that works perfectly. Now the only thing left is listening for the change to update the vote count. I aplogize for the many questions but I've been working so long in the react/vuejs ecosystem that I've forgotten how data bindings are handled in jquery.
-
That happens here https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/events.js#L43-L45,
when a vote happens (upvoted,downvote or unvote) an event is sent from the server. We listen to that withsocket.on(eventName, handler)
and update the UI in this function https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/events.js#L224