Skip to content

Commit

Permalink
fix: Update tag counts when changes are saved in the tag drawer
Browse files Browse the repository at this point in the history
* fix: courseAuthoringUrl on message listener
  • Loading branch information
ChrisChV authored and ormsbee committed May 3, 2024
1 parent 5f44c2c commit b9da896
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions cms/static/js/views/pages/container_subviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,14 @@ function($, _, gettext, BaseView, ViewUtils, XBlockViewUtils, MoveXBlockUtils, H
"message", (event) => {
// Listen any message from Manage tags drawer.
var data = event.data;
var courseAuthoringUrl = this.model.get("course_authoring_url")
var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin;
if (event.origin == courseAuthoringUrl
&& data.includes('[Manage tags drawer] Tags updated:')) {
&& data.type == 'authoring.events.tags.updated') {
// This message arrives when there is a change in the tag list.
// The message contains the new list of tags.
let jsonData = data.replace(/\[Manage tags drawer\] Tags updated: /g, "");
jsonData = JSON.parse(jsonData);
if (jsonData.contentId == this.model.id) {
this.model.set('tags', this.buildTaxonomyTree(jsonData));
data = data.data
if (data.contentId == this.model.id) {
this.model.set('tags', this.buildTaxonomyTree(data));
this.render();
}
}
Expand Down
11 changes: 5 additions & 6 deletions cms/static/js/views/tag_count.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ function($, _, BaseView, HtmlUtils) {
'message', (event) => {
// Listen any message from Manage tags drawer.
var data = event.data;
var courseAuthoringUrl = this.model.get("course_authoring_url")
var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin;
if (event.origin == courseAuthoringUrl
&& data.includes('[Manage tags drawer] Count updated:')) {
&& data.type == 'authoring.events.tags.count.updated') {
// This message arrives when there is a change in the tag list.
// The message contains the new count of tags.
let jsonData = data.replace(/\[Manage tags drawer\] Count updated: /g, "");
jsonData = JSON.parse(jsonData);
if (jsonData.contentId == this.model.get("content_id")) {
this.model.set('tags_count', jsonData.count);
data = data.data
if (data.contentId == this.model.get("content_id")) {
this.model.set('tags_count', data.count);
this.render();
}
}
Expand Down

0 comments on commit b9da896

Please sign in to comment.