discourse/plugins/chat/assets/javascripts/discourse/components/chat-header.gjs
Sérgio Saquetim 1654d529ef
DEV: Consolidate reusable components into ui-kit (#38703)
Consolidates reusable UI primitives from `app/components/`,
`app/helpers/`, and `app/modifiers/` into a dedicated `app/ui-kit/`
directory under a unified `d-` prefix naming convention. This gives
Discourse a single, discoverable home for the building-block parts of
the UI: generic primitives (buttons, inputs, modals, selects), layout
pieces (page headers, breadcrumbs, stat tiles), and lightly
Discourse-flavored display widgets (user info, badges, cook-text).

Helpers and modifiers live in `app/ui-kit/helpers/` and
`app/ui-kit/modifiers/` respectively.

### Backward compatibility

No existing imports or template invocations need to change. Old import
paths (e.g. `discourse/components/d-button`, `discourse/helpers/d-icon`)
keep working via runtime AMD `loaderShim` entries in
`app/ui-kit-shims.js`, so plugins and themes need zero changes.

An ESLint rule (shipped via `@discourse/lint-configs` 2.46.0) auto-fixes
imports in the codebase to use the new `discourse/ui-kit/...` paths.
Existing consumer files in `app/`, `admin/`, `plugins/`, and `frontend/`
have been re-imported through that rule in a single sweep, so the
codebase stays consistent.

### Tests

Test module identifiers and file paths now match the ui-kit directory
layout (`tests/integration/ui-kit/...`, `module("Integration | ui-kit |
...")`), keeping the test tree symmetric with `app/ui-kit/`.
2026-05-11 18:07:36 -03:00

67 lines
1.6 KiB
Text
Vendored

import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import getURL from "discourse/lib/get-url";
import dIcon from "discourse/ui-kit/helpers/d-icon";
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}}
>
{{dIcon "arrow-left"}}
{{this.title}}
</a>
<LinkTo @route="chat.index" class="c-heading">{{this.heading}}</LinkTo>
</div>
{{else}}
{{yield}}
{{/if}}
</template>
}