danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
594 stars 157 forks source link

add ability to reload comments after changing state #336

Open PetrDlouhy opened 3 years ago

PetrDlouhy commented 3 years ago

Few changes that allowed me to reload comments for different object after page load (for usage in modal dialog). I don't know anything about React, so the code is rather hacky, and with the version 3.0 on the way I think we don't need to put much effort into polishing this. I am putting it here just to show how I solved #335.

I am reloading the comments with:

     $.getJSON(
         "/asset-comment/" + asset_id + "/",
         function(comments_props, textStatus, jqxhr) {
            comments_props_override = {
               allow_comments: true,
               allow_feedback: true,
               show_feedback: true,
               allow_flagging: true,
               polling_interval: 5000
            };
            window.commentBox.setState({props: Object.assign(comments_props, comments_props_override)});
            window.commentBox.reload_all();
        }
      );

Where on the /asset-comment/xxxx/ url is view that just returns JSON with the comments_props.