Previously, the `{{mobile-nav}}` component required a `currentRouteName` property, passed from the router service. It would observe changes in this property, and update the UI accordingly.
If we change between routes which have the same `currentRouteName` (e.g. two different group message inboxes), then the `currentRouteName` does not change and does not trigger the observer. Currently in core, we are relying on the fact that currentRouteName temporarily enters a `.loading` substate during a transition. This will change when we remove the loading substate in the near future.
This commit refactors `{{mobile-nav}}` to inject the router directly, and use the `routeDidChange` event instead of an observer. The change is backwards compatible, but plugins passing the old `currentPath` property will be shown a deprecation notice.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import Controller, { inject as controller } from "@ember/controller";
|
|
import I18n from "I18n";
|
|
import { alias } from "@ember/object/computed";
|
|
import bootbox from "bootbox";
|
|
import { exportUserArchive } from "discourse/lib/export-csv";
|
|
import { observes } from "discourse-common/utils/decorators";
|
|
|
|
export default Controller.extend({
|
|
application: controller(),
|
|
user: controller(),
|
|
userActionType: null,
|
|
|
|
canDownloadPosts: alias("user.viewingSelf"),
|
|
|
|
@observes("userActionType", "model.stream.itemsLoaded")
|
|
_showFooter: function () {
|
|
let showFooter;
|
|
if (this.userActionType) {
|
|
const stat = (this.get("model.stats") || []).find(
|
|
(s) => s.action_type === this.userActionType
|
|
);
|
|
showFooter = stat && stat.count <= this.get("model.stream.itemsLoaded");
|
|
} else {
|
|
showFooter =
|
|
this.get("model.statsCountNonPM") <=
|
|
this.get("model.stream.itemsLoaded");
|
|
}
|
|
this.set("application.showFooter", showFooter);
|
|
},
|
|
|
|
actions: {
|
|
exportUserArchive() {
|
|
bootbox.confirm(
|
|
I18n.t("user.download_archive.confirm"),
|
|
I18n.t("no_value"),
|
|
I18n.t("yes_value"),
|
|
(confirmed) => (confirmed ? exportUserArchive() : null)
|
|
);
|
|
},
|
|
},
|
|
});
|