discourse/plugins/chat/assets/javascripts/discourse/components/chat-header.gjs
David Taylor 6f7c581a80
DEV: Bump @discourse/lint-configs and autofix (#29847)
In particular, this applies:

- new `discourse/no-implicit-this` template-lint rule
- `init`/`willDestroy` ordering enforcement
- `lines-between-class-members`
2024-11-20 14:15:04 +00:00

68 lines
1.6 KiB
Plaintext

import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import icon from "discourse-common/helpers/d-icon";
import getURL from "discourse-common/lib/get-url";
import { i18n } from "discourse-i18n";
export default class ChatHeader extends Component {
@service site;
@service siteSettings;
@service router;
@tracked previousURL;
title = i18n("chat.back_to_forum");
heading = i18n("chat.heading");
constructor() {
super(...arguments);
this.router.on("routeDidChange", this, this.#updatePreviousURL);
}
willDestroy() {
super.willDestroy(...arguments);
this.router.off("routeDidChange", this, this.#updatePreviousURL);
}
get shouldRender() {
return (
this.siteSettings.chat_enabled && this.site.mobileView && this.isChatOpen
);
}
get isChatOpen() {
return this.router.currentURL.startsWith("/chat");
}
get forumLink() {
return getURL(this.previousURL ?? this.router.rootURL);
}
#updatePreviousURL() {
if (!this.isChatOpen) {
this.previousURL = this.router.currentURL;
}
}
<template>
{{#if this.shouldRender}}
<div class="c-header">
<a
href={{this.forumLink}}
class="btn-flat back-to-forum"
title={{this.title}}
>
{{icon "arrow-left"}}
{{this.title}}
</a>
<LinkTo @route="chat.index" class="c-heading">{{this.heading}}</LinkTo>
</div>
{{else}}
{{yield}}
{{/if}}
</template>
}