REFACTOR: Clean up router usage and private APIs

This commit is contained in:
Robin Ward 2020-08-13 16:08:31 -04:00
parent 6a9bde3bf4
commit 01e213c930
5 changed files with 8 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { alias, match, gt } from "@ember/object/computed"; import { alias, gt } from "@ember/object/computed";
import Component from "@ember/component"; import Component from "@ember/component";
import { setting } from "discourse/lib/computed"; import { setting } from "discourse/lib/computed";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
@ -24,8 +24,6 @@ export default Component.extend(CardContentsBase, CleansUp, {
showBadges: setting("enable_badges"), showBadges: setting("enable_badges"),
postStream: alias("topic.postStream"), postStream: alias("topic.postStream"),
viewingTopic: match("currentPath", /^topic\./),
showMoreMembers: gt("moreMembersCount", 0), showMoreMembers: gt("moreMembersCount", 0),
group: null, group: null,

View File

@ -12,7 +12,6 @@ import CanCheckEmails from "discourse/mixins/can-check-emails";
import CardContentsBase from "discourse/mixins/card-contents-base"; import CardContentsBase from "discourse/mixins/card-contents-base";
import CleansUp from "discourse/mixins/cleans-up"; import CleansUp from "discourse/mixins/cleans-up";
import { prioritizeNameInUx } from "discourse/lib/settings"; import { prioritizeNameInUx } from "discourse/lib/settings";
import { getOwner } from "@ember/application";
export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, { export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
elementId: "user-card", elementId: "user-card",
@ -201,10 +200,7 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
composePM(user, post) { composePM(user, post) {
this._close(); this._close();
this.composePrivateMessage(user, post);
getOwner(this)
.lookup("router:main")
.send("composePrivateMessage", user, post);
}, },
cancelFilter() { cancelFilter() {

View File

@ -1,10 +1,9 @@
import { inject as service } from "@ember/service";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import DiscourseURL, { userPath, groupPath } from "discourse/lib/url"; import DiscourseURL, { userPath, groupPath } from "discourse/lib/url";
export default Controller.extend({ export default Controller.extend({
application: controller(),
topic: controller(), topic: controller(),
router: service(),
actions: { actions: {
togglePosts(user) { togglePosts(user) {

View File

@ -5,14 +5,17 @@ import afterTransition from "discourse/lib/after-transition";
import DiscourseURL from "discourse/lib/url"; import DiscourseURL from "discourse/lib/url";
import Mixin from "@ember/object/mixin"; import Mixin from "@ember/object/mixin";
import { escapeExpression } from "discourse/lib/utilities"; import { escapeExpression } from "discourse/lib/utilities";
import { inject as service } from "@ember/service";
export default Mixin.create({ export default Mixin.create({
router: service(),
elementId: null, //click detection added for data-{elementId} elementId: null, //click detection added for data-{elementId}
triggeringLinkClass: null, //the <a> classname where this card should appear triggeringLinkClass: null, //the <a> classname where this card should appear
_showCallback: null, //username, $target - load up data for when show is called, should call this._positionCard($target) when it's done. _showCallback: null, //username, $target - load up data for when show is called, should call this._positionCard($target) when it's done.
postStream: alias("topic.postStream"), postStream: alias("topic.postStream"),
viewingTopic: match("currentPath", /^topic\./), viewingTopic: match("router.currentRouteName", /^topic\./),
visible: false, visible: false,
username: null, username: null,

View File

@ -3,14 +3,13 @@
{{/if}} {{/if}}
{{user-card-contents {{user-card-contents
currentPath=router._router.currentPath
topic=topic.model topic=topic.model
showUser=(action "showUser") showUser=(action "showUser")
togglePosts=(action "togglePosts") togglePosts=(action "togglePosts")
composePrivateMessage=(route-action "composePrivateMessage")
createNewMessageViaParams=(route-action "createNewMessageViaParams")}} createNewMessageViaParams=(route-action "createNewMessageViaParams")}}
{{group-card-contents {{group-card-contents
currentPath=router._router.currentPath
topic=topic.model topic=topic.model
showUser=(action "showUser") showUser=(action "showUser")
showGroup=(action "showGroup") showGroup=(action "showGroup")