discourse/app/assets/javascripts/discourse/app/controllers/user-private-messages-group.js
Alan Guo Xiang Tan 9a18c8032a
UX: Don't block render of user messages secondary nav for tracking state (#21965)
Why is this change required?

Right now, we're awaiting on the promise returned by
`this.pmTopicTrackingState.startTracking()` which blocks the rendering
of the template until the promise resolves. However, this blocking of
the rendering ends up introducing yet another intermediate loading state
in the UI which we find unsightly. Instead of blocking the rendering, we
allow the promise to resolve in the background and display the
new/unread counts when the promise resolves.
2023-06-07 12:37:05 +08:00

52 lines
1.2 KiB
JavaScript

import I18n from "I18n";
import Controller, { inject as controller } from "@ember/controller";
import { action, computed } from "@ember/object";
export default class extends Controller {
@controller user;
get viewingSelf() {
return this.user.viewingSelf;
}
@computed(
"pmTopicTrackingState.newIncoming.[]",
"pmTopicTrackingState.statesModificationCounter",
"pmTopicTrackingState.isTracking"
)
get newLinkText() {
return this.#linkText("new");
}
@computed(
"pmTopicTrackingState.newIncoming.[]",
"pmTopicTrackingState.statesModificationCounter",
"pmTopicTrackingState.isTracking"
)
get unreadLinkText() {
return this.#linkText("unread");
}
get navigationControlsButton() {
return document.getElementById("navigation-controls__button");
}
#linkText(type) {
const count = this.pmTopicTrackingState?.lookupCount(type, {
inboxFilter: "group",
groupName: this.group.name,
});
if (count === 0) {
return I18n.t(`user.messages.${type}`);
} else {
return I18n.t(`user.messages.${type}_with_count`, { count });
}
}
@action
changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id"));
}
}