This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/user-activity.js
David Taylor 1844bde57c
FIX: Allow mobile-nav to work without loading transitions (#12184)
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.
2021-02-23 11:16:40 +00:00

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)
);
},
},
});