Skip to content

Commit

Permalink
fix: sometimes components could not be added
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Oct 20, 2024
1 parent 12f341c commit 5939b5d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cms/static/js/views/modals/select_v2_library_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function($, _, gettext, BaseModal) {
initialize: function() {
BaseModal.prototype.initialize.call(this);
// Add event listen to close picker when the iframe tells us to
window.addEventListener("message", function (event) {
const handleMessage = (event) => {
if (event.data?.type === 'pickerComponentSelected') {
var requestData = {
library_content_key: event.data.usageKey,
Expand All @@ -29,7 +29,14 @@ function($, _, gettext, BaseModal) {
this.callback(requestData);
this.hide();
}
}.bind(this), { once: true }, false);
};
this.messageListener = window.addEventListener("message", handleMessage);
this.cleanupListener = () => { window.removeEventListener("message", handleMessage) };
},

hide: function() {
BaseModal.prototype.hide.call(this);
this.cleanupListener();
},

/**
Expand Down

0 comments on commit 5939b5d

Please sign in to comment.