DEV: Simplify TopicNotificationsButton (#29465)

This commit is contained in:
Jarek Radosz 2024-10-29 16:27:23 +01:00 committed by GitHub
parent 5a56f6fe01
commit cc447a1ae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 57 deletions

View File

@ -92,6 +92,7 @@
{{#if this.showNotificationsButton}} {{#if this.showNotificationsButton}}
<TopicNotificationsButton <TopicNotificationsButton
@topic={{this.topic}} @topic={{this.topic}}
@expanded={{true}}
class="notifications-button-footer" class="notifications-button-footer"
/> />

View File

@ -12,7 +12,6 @@
@jumpToIndex={{@jumpToIndex}} @jumpToIndex={{@jumpToIndex}}
@jumpToPostPrompt={{@jumpToPostPrompt}} @jumpToPostPrompt={{@jumpToPostPrompt}}
@fullscreen={{@fullscreen}} @fullscreen={{@fullscreen}}
@mobileView={{@mobileView}}
@toggleMultiSelect={{@toggleMultiSelect}} @toggleMultiSelect={{@toggleMultiSelect}}
@showTopicSlowModeUpdate={{@showTopicSlowModeUpdate}} @showTopicSlowModeUpdate={{@showTopicSlowModeUpdate}}
@showTopReplies={{@showTopReplies}} @showTopReplies={{@showTopReplies}}

View File

@ -173,12 +173,7 @@
{{/if}} {{/if}}
{{#if this.currentUser}} {{#if this.currentUser}}
<TopicNotificationsButton <TopicNotificationsButton @topic={{@model}} @expanded={{false}} />
@topic={{@model}}
@showFullTitle={{false}}
@appendReason={{false}}
@showCaret={{false}}
/>
{{/if}} {{/if}}
<PluginOutlet <PluginOutlet

View File

@ -29,6 +29,7 @@ export function setDesktopScrollAreaHeight(
export default class TopicTimelineScrollArea extends Component { export default class TopicTimelineScrollArea extends Component {
@service appEvents; @service appEvents;
@service site;
@service siteSettings; @service siteSettings;
@service currentUser; @service currentUser;
@ -57,7 +58,7 @@ export default class TopicTimelineScrollArea extends Component {
constructor() { constructor() {
super(...arguments); super(...arguments);
if (!this.args.mobileView) { if (this.site.desktopView) {
// listen for scrolling event to update timeline // listen for scrolling event to update timeline
this.appEvents.on("topic:current-post-scrolled", this.postScrolled); this.appEvents.on("topic:current-post-scrolled", this.postScrolled);
// listen for composer sizing changes to update timeline // listen for composer sizing changes to update timeline
@ -102,7 +103,7 @@ export default class TopicTimelineScrollArea extends Component {
} }
get displayTimeLineScrollArea() { get displayTimeLineScrollArea() {
if (this.args.mobileView) { if (this.site.mobileView) {
return true; return true;
} }
@ -121,7 +122,7 @@ export default class TopicTimelineScrollArea extends Component {
} }
get topicTitle() { get topicTitle() {
return htmlSafe(this.args.mobileView ? this.args.model.fancyTitle : ""); return htmlSafe(this.site.mobileView ? this.args.model.fancyTitle : "");
} }
get showTags() { get showTags() {
@ -143,7 +144,7 @@ export default class TopicTimelineScrollArea extends Component {
} }
get showDockedButton() { get showDockedButton() {
return !this.args.mobileView && this.hasBackPosition && !this.showButton; return this.site.desktopView && this.hasBackPosition && !this.showButton;
} }
get hasBackPosition() { get hasBackPosition() {
@ -177,10 +178,10 @@ export default class TopicTimelineScrollArea extends Component {
const availableHeight = const availableHeight =
(window.innerHeight - composerHeight - headerHeight) / 2; (window.innerHeight - composerHeight - headerHeight) / 2;
const minHeight = this.args.mobileView const minHeight = this.site.mobileView
? DEFAULT_MIN_SCROLLAREA_HEIGHT ? DEFAULT_MIN_SCROLLAREA_HEIGHT
: desktopMinScrollAreaHeight; : desktopMinScrollAreaHeight;
const maxHeight = this.args.mobileView const maxHeight = this.site.mobileView
? DEFAULT_MAX_SCROLLAREA_HEIGHT ? DEFAULT_MAX_SCROLLAREA_HEIGHT
: desktopMaxScrollAreaHeight; : desktopMaxScrollAreaHeight;
@ -426,7 +427,7 @@ export default class TopicTimelineScrollArea extends Component {
willDestroy() { willDestroy() {
super.willDestroy(...arguments); super.willDestroy(...arguments);
if (!this.args.mobileView) { if (this.site.desktopView) {
this.intersectionObserver?.disconnect(); this.intersectionObserver?.disconnect();
this.intersectionObserver = null; this.intersectionObserver = null;

View File

@ -276,7 +276,6 @@
@convertToPublicTopic={{action "convertToPublicTopic"}} @convertToPublicTopic={{action "convertToPublicTopic"}}
@convertToPrivateMessage={{action "convertToPrivateMessage"}} @convertToPrivateMessage={{action "convertToPrivateMessage"}}
@fullscreen={{info.topicProgressExpanded}} @fullscreen={{info.topicProgressExpanded}}
@mobileView={{this.site.mobileView}}
/> />
{{else}} {{else}}
<TopicProgress <TopicProgress

View File

@ -47,7 +47,7 @@ module(
state.topic = buildTopic.call(this, { level: 1 }); state.topic = buildTopic.call(this, { level: 1 });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{state.topic}} /> <TopicNotificationsButton @topic={{state.topic}} @expanded={{true}} />
</template>); </template>);
assert.strictEqual( assert.strictEqual(
@ -74,7 +74,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert.strictEqual( assert.strictEqual(
@ -89,7 +89,7 @@ module(
const topic = buildTopic.call(this, { level: 2 }); const topic = buildTopic.call(this, { level: 2 });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -105,7 +105,7 @@ module(
state.topic = buildTopic.call(this, { level: 2 }); state.topic = buildTopic.call(this, { level: 2 });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{state.topic}} /> <TopicNotificationsButton @topic={{state.topic}} @expanded={{true}} />
</template>); </template>);
state.topic = buildTopic.call(this, { level: 3, reason: 999 }); state.topic = buildTopic.call(this, { level: 3, reason: 999 });
@ -128,7 +128,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -148,7 +148,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -168,7 +168,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -188,7 +188,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -208,7 +208,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert
@ -228,7 +228,7 @@ module(
}); });
await render(<template> await render(<template>
<TopicNotificationsButton @topic={{topic}} /> <TopicNotificationsButton @topic={{topic}} @expanded={{true}} />
</template>); </template>);
assert assert

View File

@ -20,18 +20,6 @@ export default class TopicNotificationsButton extends Component {
return this.args.topic.get("details.notification_level"); return this.args.topic.get("details.notification_level");
} }
get appendReason() {
return this.args.appendReason ?? true;
}
get showFullTitle() {
return this.args.showFullTitle ?? true;
}
get showCaret() {
return this.args.showCaret ?? true;
}
get reasonText() { get reasonText() {
const topic = this.args.topic; const topic = this.args.topic;
const level = topic.get("details.notification_level") ?? 1; const level = topic.get("details.notification_level") ?? 1;
@ -97,6 +85,16 @@ export default class TopicNotificationsButton extends Component {
return false; return false;
} }
get conditionalWrapper() {
if (this.args.expanded) {
return <template><p class="reason">{{yield}}</p></template>;
} else {
return <template>
{{! template-lint-disable no-yield-only}}{{yield}}
</template>;
}
}
@action @action
async changeTopicNotificationLevel(levelId) { async changeTopicNotificationLevel(levelId) {
if (levelId === this.notificationLevel) { if (levelId === this.notificationLevel) {
@ -114,34 +112,22 @@ export default class TopicNotificationsButton extends Component {
<template> <template>
<div class="topic-notifications-button" ...attributes> <div class="topic-notifications-button" ...attributes>
{{#if this.appendReason}} <this.conditionalWrapper>
<p class="reason">
<TopicNotificationsOptions <TopicNotificationsOptions
@value={{this.notificationLevel}} @value={{this.notificationLevel}}
@topic={{@topic}} @topic={{@topic}}
@onChange={{this.changeTopicNotificationLevel}} @onChange={{this.changeTopicNotificationLevel}}
@options={{hash @options={{hash
icon=(if this.isLoading "spinner") icon=(if this.isLoading "spinner")
showFullTitle=this.showFullTitle showFullTitle=@expanded
showCaret=this.showCaret showCaret=@expanded
headerAriaLabel=(i18n "topic.notifications.title") headerAriaLabel=(i18n "topic.notifications.title")
}} }}
/> />
{{#if @expanded}}
<span class="text">{{htmlSafe this.reasonText}}</span> <span class="text">{{htmlSafe this.reasonText}}</span>
</p>
{{else}}
<TopicNotificationsOptions
@value={{this.notificationLevel}}
@topic={{@topic}}
@onChange={{this.changeTopicNotificationLevel}}
@options={{hash
icon=(if this.isLoading "spinner")
showFullTitle=this.showFullTitle
showCaret=this.showCaret
headerAriaLabel=(i18n "topic.notifications.title")
}}
/>
{{/if}} {{/if}}
</this.conditionalWrapper>
</div> </div>
</template> </template>
} }

View File

@ -1,3 +1,7 @@
<StyleguideExample @title="<TopicNotificationsButton>"> <StyleguideExample @title="<TopicNotificationsButton> expanded">
<TopicNotificationsButton @topic={{@dummy.topic}} /> <TopicNotificationsButton @topic={{@dummy.topic}} @expanded={{true}} />
</StyleguideExample>
<StyleguideExample @title="<TopicNotificationsButton>">
<TopicNotificationsButton @topic={{@dummy.topic}} @expanded={{false}} />
</StyleguideExample> </StyleguideExample>