mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 07:43:48 +08:00
DEV: move CleansUp mixin code to components (#30292)
* DEV: move cleans-up event listeners directly to components * DEV: inline logic from unnecessary cleanUp func in GroupCardContents
This commit is contained in:
parent
d416b7c7dd
commit
a141a096d1
|
@ -2,11 +2,11 @@ import { action } from "@ember/object";
|
||||||
import { alias, gt } from "@ember/object/computed";
|
import { alias, gt } from "@ember/object/computed";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import { classNameBindings, classNames } from "@ember-decorators/component";
|
import { classNameBindings, classNames } from "@ember-decorators/component";
|
||||||
|
import { on } from "@ember-decorators/object";
|
||||||
import CardContentsBase from "discourse/components/card-contents-base";
|
import CardContentsBase from "discourse/components/card-contents-base";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { groupPath } from "discourse/lib/url";
|
import { groupPath } from "discourse/lib/url";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const maxMembersToDisplay = 10;
|
const maxMembersToDisplay = 10;
|
||||||
|
@ -19,9 +19,7 @@ const maxMembersToDisplay = 10;
|
||||||
"isFixed:fixed",
|
"isFixed:fixed",
|
||||||
"groupClass"
|
"groupClass"
|
||||||
)
|
)
|
||||||
export default class GroupCardContents extends CardContentsBase.extend(
|
export default class GroupCardContents extends CardContentsBase {
|
||||||
CleansUp
|
|
||||||
) {
|
|
||||||
@service composer;
|
@service composer;
|
||||||
@setting("allow_profile_backgrounds") allowBackgrounds;
|
@setting("allow_profile_backgrounds") allowBackgrounds;
|
||||||
@setting("enable_badges") showBadges;
|
@setting("enable_badges") showBadges;
|
||||||
|
@ -54,6 +52,16 @@ export default class GroupCardContents extends CardContentsBase.extend(
|
||||||
return groupPath(group.name);
|
return groupPath(group.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@on("didInsertElement")
|
||||||
|
_inserted() {
|
||||||
|
this.appEvents.on("dom:clean", this, this._close);
|
||||||
|
}
|
||||||
|
|
||||||
|
@on("didDestroyElement")
|
||||||
|
_destroyed() {
|
||||||
|
this.appEvents.off("dom:clean", this, this._close);
|
||||||
|
}
|
||||||
|
|
||||||
async _showCallback(username) {
|
async _showCallback(username) {
|
||||||
this.setProperties({ visible: true, loading: true });
|
this.setProperties({ visible: true, loading: true });
|
||||||
|
|
||||||
|
@ -81,10 +89,6 @@ export default class GroupCardContents extends CardContentsBase.extend(
|
||||||
super._close(...arguments);
|
super._close(...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUp() {
|
|
||||||
this._close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
close(event) {
|
close(event) {
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { action } from "@ember/object";
|
||||||
import { scheduleOnce } from "@ember/runloop";
|
import { scheduleOnce } from "@ember/runloop";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import { classNameBindings } from "@ember-decorators/component";
|
import { classNameBindings } from "@ember-decorators/component";
|
||||||
|
import { on } from "@ember-decorators/object";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
|
||||||
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ function entranceDate(dt, showTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@classNameBindings("visible::hidden")
|
@classNameBindings("visible::hidden")
|
||||||
export default class TopicEntrance extends Component.extend(CleansUp) {
|
export default class TopicEntrance extends Component {
|
||||||
@service router;
|
@service router;
|
||||||
@service session;
|
@service session;
|
||||||
@service historyStore;
|
@service historyStore;
|
||||||
|
@ -72,9 +72,15 @@ export default class TopicEntrance extends Component.extend(CleansUp) {
|
||||||
return entranceDate(bumpedDate, showTime);
|
return entranceDate(bumpedDate, showTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
didInsertElement() {
|
@on("didInsertElement")
|
||||||
super.didInsertElement(...arguments);
|
_inserted() {
|
||||||
this.appEvents.on("topic-entrance:show", this, "_show");
|
this.appEvents.on("topic-entrance:show", this, "_show");
|
||||||
|
this.appEvents.on("dom:clean", this, this.cleanUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@on("didDestroyElement")
|
||||||
|
_destroyed() {
|
||||||
|
this.appEvents.off("dom:clean", this, this.cleanUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_setCSS() {
|
_setCSS() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
classNameBindings,
|
classNameBindings,
|
||||||
classNames,
|
classNames,
|
||||||
} from "@ember-decorators/component";
|
} from "@ember-decorators/component";
|
||||||
import { observes } from "@ember-decorators/object";
|
import { observes, on } from "@ember-decorators/object";
|
||||||
import CardContentsBase from "discourse/components/card-contents-base";
|
import CardContentsBase from "discourse/components/card-contents-base";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import { durationTiny } from "discourse/lib/formatter";
|
import { durationTiny } from "discourse/lib/formatter";
|
||||||
|
@ -16,7 +16,6 @@ import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
import { escapeExpression } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
@ -33,8 +32,7 @@ import { i18n } from "discourse-i18n";
|
||||||
)
|
)
|
||||||
@attributeBindings("ariaLabel:aria-label")
|
@attributeBindings("ariaLabel:aria-label")
|
||||||
export default class UserCardContents extends CardContentsBase.extend(
|
export default class UserCardContents extends CardContentsBase.extend(
|
||||||
CanCheckEmails,
|
CanCheckEmails
|
||||||
CleansUp
|
|
||||||
) {
|
) {
|
||||||
elementId = "user-card";
|
elementId = "user-card";
|
||||||
avatarSelector = "[data-user-card]";
|
avatarSelector = "[data-user-card]";
|
||||||
|
@ -205,6 +203,16 @@ export default class UserCardContents extends CardContentsBase.extend(
|
||||||
return profileHidden || inactive;
|
return profileHidden || inactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@on("didInsertElement")
|
||||||
|
_inserted() {
|
||||||
|
this.appEvents.on("dom:clean", this, this.cleanUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@on("didDestroyElement")
|
||||||
|
_destroyed() {
|
||||||
|
this.appEvents.off("dom:clean", this, this.cleanUp);
|
||||||
|
}
|
||||||
|
|
||||||
async _showCallback(username) {
|
async _showCallback(username) {
|
||||||
this.setProperties({ visible: true, loading: true });
|
this.setProperties({ visible: true, loading: true });
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
import { on } from "@ember/object/evented";
|
|
||||||
import Mixin from "@ember/object/mixin";
|
|
||||||
|
|
||||||
// Include this mixin if you want to be notified when the dom should be
|
|
||||||
// cleaned (usually on route change.)
|
|
||||||
export default Mixin.create({
|
|
||||||
_initializeChooser: on("didInsertElement", function () {
|
|
||||||
this.appEvents.on("dom:clean", this, "cleanUp");
|
|
||||||
}),
|
|
||||||
|
|
||||||
_clearChooser: on("willDestroyElement", function () {
|
|
||||||
this.appEvents.off("dom:clean", this, "cleanUp");
|
|
||||||
}),
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user