DEV: Refactor UnreadIndicator (#28969)
Moves related code from topic-cell to the component. Also fixes a couple autotracking cases in topic-cell.
This commit is contained in:
parent
50cb7b897e
commit
1ba8b6b22a
|
@ -15,48 +15,12 @@ import categoryLink from "discourse/helpers/category-link";
|
||||||
import discourseTags from "discourse/helpers/discourse-tags";
|
import discourseTags from "discourse/helpers/discourse-tags";
|
||||||
import topicFeaturedLink from "discourse/helpers/topic-featured-link";
|
import topicFeaturedLink from "discourse/helpers/topic-featured-link";
|
||||||
import { groupPath } from "discourse/lib/url";
|
import { groupPath } from "discourse/lib/url";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
export default class TopicCell extends Component {
|
export default class TopicCell extends Component {
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
@service messageBus;
|
@service messageBus;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super(...arguments);
|
|
||||||
|
|
||||||
if (this.includeUnreadIndicator) {
|
|
||||||
this.messageBus.subscribe(this.unreadIndicatorChannel, this.onMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
willDestroy() {
|
|
||||||
super.willDestroy(...arguments);
|
|
||||||
|
|
||||||
this.messageBus.unsubscribe(this.unreadIndicatorChannel, this.onMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@bind
|
|
||||||
onMessage(data) {
|
|
||||||
const nodeClassList = document.querySelector(
|
|
||||||
`.indicator-topic-${data.topic_id}`
|
|
||||||
).classList;
|
|
||||||
|
|
||||||
nodeClassList.toggle("read", !data.show_indicator);
|
|
||||||
}
|
|
||||||
|
|
||||||
get unreadIndicatorChannel() {
|
|
||||||
return `/private-messages/unread-indicator/${this.args.topic.id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
get includeUnreadIndicator() {
|
|
||||||
return typeof this.args.topic.unread_by_group_member !== "undefined";
|
|
||||||
}
|
|
||||||
|
|
||||||
get unreadClass() {
|
|
||||||
return this.args.topic.unread_by_group_member ? "" : "read";
|
|
||||||
}
|
|
||||||
|
|
||||||
get newDotText() {
|
get newDotText() {
|
||||||
return this.currentUser?.trust_level > 0
|
return this.currentUser?.trust_level > 0
|
||||||
? ""
|
? ""
|
||||||
|
@ -64,11 +28,11 @@ export default class TopicCell extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
get participantGroups() {
|
get participantGroups() {
|
||||||
if (!this.args.topic.participant_groups) {
|
if (!this.args.topic.get("participant_groups")) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.args.topic.participant_groups.map((name) => ({
|
return this.args.topic.get("participant_groups").map((name) => ({
|
||||||
name,
|
name,
|
||||||
url: groupPath(name),
|
url: groupPath(name),
|
||||||
}));
|
}));
|
||||||
|
@ -115,11 +79,7 @@ export default class TopicCell extends Component {
|
||||||
@outletArgs={{hash topic=@topic}}
|
@outletArgs={{hash topic=@topic}}
|
||||||
/>
|
/>
|
||||||
{{~! no whitespace ~}}
|
{{~! no whitespace ~}}
|
||||||
<UnreadIndicator
|
<UnreadIndicator @topic={{@topic}} />
|
||||||
@includeUnreadIndicator={{this.includeUnreadIndicator}}
|
|
||||||
@topicId={{@topic.id}}
|
|
||||||
class={{this.unreadClass}}
|
|
||||||
/>
|
|
||||||
{{~#if @showTopicPostBadges~}}
|
{{~#if @showTopicPostBadges~}}
|
||||||
<TopicPostBadges
|
<TopicPostBadges
|
||||||
@unreadPosts={{@topic.unread_posts}}
|
@unreadPosts={{@topic.unread_posts}}
|
||||||
|
|
|
@ -1,21 +1,43 @@
|
||||||
import { concat } from "@ember/helper";
|
import Component from "@glimmer/component";
|
||||||
import concatClass from "discourse/helpers/concat-class";
|
import { service } from "@ember/service";
|
||||||
import icon from "discourse-common/helpers/d-icon";
|
import icon from "discourse-common/helpers/d-icon";
|
||||||
import i18n from "discourse-common/helpers/i18n";
|
import i18n from "discourse-common/helpers/i18n";
|
||||||
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const UnreadIndicator = <template>
|
export default class UnreadIndicator extends Component {
|
||||||
{{~#if @includeUnreadIndicator~}}
|
@service messageBus;
|
||||||
<span
|
|
||||||
title={{i18n "topic.unread_indicator"}}
|
|
||||||
class={{concatClass
|
|
||||||
"badge badge-notification unread-indicator"
|
|
||||||
(concat "indicator-topic-" @topicId)
|
|
||||||
}}
|
|
||||||
...attributes
|
|
||||||
>
|
|
||||||
{{~icon "asterisk"~}}
|
|
||||||
</span>
|
|
||||||
{{~/if~}}
|
|
||||||
</template>;
|
|
||||||
|
|
||||||
export default UnreadIndicator;
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.messageBus.subscribe(this.unreadIndicatorChannel, this.onMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
willDestroy() {
|
||||||
|
super.willDestroy(...arguments);
|
||||||
|
this.messageBus.unsubscribe(this.unreadIndicatorChannel, this.onMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@bind
|
||||||
|
onMessage(data) {
|
||||||
|
this.args.topic.set("unread_by_group_member", data.show_indicator);
|
||||||
|
}
|
||||||
|
|
||||||
|
get unreadIndicatorChannel() {
|
||||||
|
return `/private-messages/unread-indicator/${this.args.topic.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isUnread() {
|
||||||
|
return typeof this.args.topic.get("unread_by_group_member") !== "undefined";
|
||||||
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
{{~#if this.isUnread~}}
|
||||||
|
<span
|
||||||
|
title={{i18n "topic.unread_indicator"}}
|
||||||
|
class="badge badge-notification unread-indicator"
|
||||||
|
>
|
||||||
|
{{~icon "asterisk"~}}
|
||||||
|
</span>
|
||||||
|
{{~/if~}}
|
||||||
|
</template>
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue