FIX: Ensure sidebar class is removed when component destroyed (#111)

This commit is contained in:
David Taylor 2022-02-28 11:51:29 +00:00 committed by GitHub
parent 46e0a2aa46
commit fa490337ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -7,6 +7,8 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { later } from "@ember/runloop";
import { inject as service } from "@ember/service";
const SIDEBAR_BODY_CLASS = "subscription-campaign-sidebar";
export default Component.extend({
router: service(),
dismissed: false,
@ -68,9 +70,9 @@ export default Component.extend({
didInsertElement() {
this._super(...arguments);
if (this.isSidebar && this.shouldShow && !this.site.mobileView) {
document.body.classList.add("subscription-campaign-sidebar");
document.body.classList.add(SIDEBAR_BODY_CLASS);
} else {
document.body.classList.remove("subscription-campaign-sidebar");
document.body.classList.remove(SIDEBAR_BODY_CLASS);
}
// makes sure to only play animation once, & not repeat on reload
@ -93,6 +95,10 @@ export default Component.extend({
}
},
willDestroyElement() {
document.body.classList.remove(SIDEBAR_BODY_CLASS);
},
@discourseComputed("backgroundImageUrl")
bannerInfoStyle(backgroundImageUrl) {
if (!backgroundImageUrl) {
@ -139,7 +145,7 @@ export default Component.extend({
@observes("dismissed")
_updateBodyClasses() {
if (this.dismissed) {
document.body.classList.remove("subscription-campaign-sidebar");
document.body.classList.remove(SIDEBAR_BODY_CLASS);
}
},