A platform for community discussion. Free, open, simple.
DEV: Render more-topics tabs inside topic list header (#38127)
Krisb89e514552fd
diff --git a/app/assets/stylesheets/common/components/more-topics.scss b/app/assets/stylesheets/common/components/more-topics.scssindex 84f70f0107e..5034a5bce53 100644--- a/app/assets/stylesheets/common/components/more-topics.scss+++ b/app/assets/stylesheets/common/components/more-topics.scss@@ -52,22 +52,16 @@}.more-topics__list {- .topic-list-header::after {- content: "";- display: block;- height: 12px;- }-.topic-list-body {border-top: none;+ }- .topic-list-item {- &:first-child td {- padding-top: 0;- }+ .topic-list-header:has(.nav-pills) {+ th.topic-list-data {+ padding-bottom: 0;- &:last-of-type {- border-bottom: none;+ &:first-of-type {+ padding-left: 0;}}}diff --git a/app/assets/stylesheets/desktop/components/_index.scss b/app/assets/stylesheets/desktop/components/_index.scssindex 0750dfa2ab6..973ee8c83fe 100644--- a/app/assets/stylesheets/desktop/components/_index.scss+++ b/app/assets/stylesheets/desktop/components/_index.scss@@ -1,6 +1,5 @@@import "drafts-dropdown-menu";@import "header-search";-@import "more-topics";@import "sidebar/edit-navigation-menu/tags-modal";@import "sidebar/sidebar-section";@import "user-card";diff --git a/app/assets/stylesheets/desktop/components/more-topics.scss b/app/assets/stylesheets/desktop/components/more-topics.scssdeleted file mode 100644index 11ee3aa866b..00000000000--- a/app/assets/stylesheets/desktop/components/more-topics.scss+++ /dev/null@@ -1,15 +0,0 @@-.more-topics__container {- .nav {- position: absolute;-- li {- margin-right: 0;- }- }-- .more-topics__lists:not(.single-list) {- .topic-list-header .default {- visibility: hidden;- }- }-}diff --git a/frontend/discourse/app/components/more-topics.gjs b/frontend/discourse/app/components/more-topics.gjsindex fe9a3665587..54fca639067 100644--- a/frontend/discourse/app/components/more-topics.gjs+++ b/frontend/discourse/app/components/more-topics.gjs@@ -1,13 +1,9 @@import Component from "@glimmer/component";-import { cached, tracked } from "@glimmer/tracking";-import { fn } from "@ember/helper";-import { action } from "@ember/object";import { service } from "@ember/service";-import DButton from "discourse/components/d-button";+import { modifier } from "ember-modifier";import BrowseMore from "discourse/components/more-topics/browse-more";import concatClass from "discourse/helpers/concat-class";-import { applyValueTransformer } from "discourse/lib/transformer";-import { eq, gt } from "discourse/truth-helpers";+import { eq } from "discourse/truth-helpers";export let registeredTabs = [];@@ -16,88 +12,23 @@ export function clearRegisteredTabs() {}export default class MoreTopics extends Component {- @service currentUser;- @service keyValueStore;+ @service moreTopicsTabs;- @tracked selectedTab = this.initialTab;-- get initialTab() {- let savedId = this.keyValueStore.get(- `more-topics-preference-${this.context}`- );-- // Fallback to the old setting- savedId ||= this.keyValueStore.get("more-topics-list-preference");-- return (- (savedId && this.tabs.find((tab) => tab.id === savedId)) || this.tabs[0]- );- }-- get activeTab() {- return this.tabs.find((tab) => tab === this.selectedTab) || this.tabs[0];- }-- get context() {- return this.args.topic.get("isPrivateMessage") ? "pm" : "topic";- }-- @cached- get tabs() {- const defaultTabs = registeredTabs.filter((tab) =>- tab.condition({ topic: this.args.topic, context: this.context })- );-- return applyValueTransformer("more-topics-tabs", defaultTabs, {- currentContext: this.context,- user: this.currentUser,- topic: this.args.topic,- });- }-- @action- selectTab(tab) {- this.selectedTab = tab;- this.keyValueStore.set({- key: `more-topics-preference-${this.context}`,- value: tab.id,- });- }-- @action- isActiveTab(tab) {- return tab?.id === this.selectedTab?.id;- }+ syncTopic = modifier((_, [topic]) => {+ this.moreTopicsTabs.setup(topic);+ return () => this.moreTopicsTabs.teardown();+ });<template>- <div class="more-topics__container">- {{#if (gt this.tabs.length 1)}}- <div class="row">- <ul class="nav nav-pills">- {{#each this.tabs as |tab|}}- <li>- <DButton- @action={{fn this.selectTab tab}}- @translatedLabel={{tab.name}}- @translatedTitle={{tab.name}}- @icon={{tab.icon}}- class={{if (this.isActiveTab tab) "active"}}- tabindex={{if (this.isActiveTab tab) -1 0}}- />- </li>- {{/each}}- </ul>- </div>- {{/if}}-- {{#if this.activeTab}}+ <div class="more-topics__container" {{this.syncTopic @topic}}>+ {{#if this.moreTopicsTabs.selectedTab}}<divclass={{concatClass"more-topics__lists"- (if (eq this.tabs.length 1) "single-list")+ (if (eq this.moreTopicsTabs.tabs.length 1) "single-list")}}>- <this.activeTab.component @topic={{@topic}} />+ <this.moreTopicsTabs.selectedTab.component @topic={{@topic}} /></div>{{#if @topic.suggestedTopics.length}}diff --git a/frontend/discourse/app/components/topic-list/header/topic-cell.gjs b/frontend/discourse/app/components/topic-list/header/topic-cell.gjsindex c0d93833fba..c2af06a581f 100644--- a/frontend/discourse/app/components/topic-list/header/topic-cell.gjs+++ b/frontend/discourse/app/components/topic-list/header/topic-cell.gjs@@ -1,19 +1,48 @@+import Component from "@glimmer/component";+import { fn } from "@ember/helper";+import { service } from "@ember/service";+import DButton from "discourse/components/d-button";import SortableColumn from "./sortable-column";-const TopicCell = <template>- <SortableColumn- @order="default"- @category={{@category}}- @activeOrder={{@activeOrder}}- @changeSort={{@changeSort}}- @ascending={{@ascending}}- @name={{@name}}- @bulkSelectEnabled={{@bulkSelectEnabled}}- @showBulkToggle={{@showBulkToggle}}- @canBulkSelect={{@canBulkSelect}}- @canDoBulkActions={{@canDoBulkActions}}- @bulkSelectHelper={{@bulkSelectHelper}}- />-</template>;+export default class TopicCell extends Component {+ @service moreTopicsTabs;-export default TopicCell;+ get showTabs() {+ return this.moreTopicsTabs.tabs.length > 1;+ }++ <template>+ {{#if this.showTabs}}+ <th scope="col" class="topic-list-data default">+ <ul class="nav nav-pills">+ {{#each this.moreTopicsTabs.tabs as |tab|}}+ <li>+ <DButton+ @action={{fn this.moreTopicsTabs.selectTab tab}}+ @translatedLabel={{tab.name}}+ @translatedTitle={{tab.name}}+ @icon={{tab.icon}}+ class={{if (this.moreTopicsTabs.isActiveTab tab) "active"}}+ tabindex={{if (this.moreTopicsTabs.isActiveTab tab) -1 0}}+ />+ </li>+ {{/each}}+ </ul>+ </th>+ {{else}}+ <SortableColumn+ @order="default"+ @category={{@category}}+ @activeOrder={{@activeOrder}}+ @changeSort={{@changeSort}}+ @ascending={{@ascending}}+ @name={{@name}}+ @bulkSelectEnabled={{@bulkSelectEnabled}}+ @showBulkToggle={{@showBulkToggle}}+ @canBulkSelect={{@canBulkSelect}}+ @canDoBulkActions={{@canDoBulkActions}}+ @bulkSelectHelper={{@bulkSelectHelper}}+ />+ {{/if}}+ </template>+}diff --git a/frontend/discourse/app/services/more-topics-tabs.js b/frontend/discourse/app/services/more-topics-tabs.jsnew file mode 100644index 00000000000..ec2cc167f96--- /dev/null+++ b/frontend/discourse/app/services/more-topics-tabs.js@@ -0,0 +1,66 @@+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import Service, { service } from "@ember/service";+import { registeredTabs } from "discourse/components/more-topics";+import { disableImplicitInjections } from "discourse/lib/implicit-injections";+import { applyValueTransformer } from "discourse/lib/transformer";++@disableImplicitInjections+export default class MoreTopicsTabsService extends Service {+ @service currentUser;+ @service keyValueStore;++ @tracked topic = null;+ @tracked preferredTab = null;++ get context() {+ return this.topic?.get("isPrivateMessage") ? "pm" : "topic";+ }++ get tabs() {+ if (!this.topic) {+ return [];+ }+ const defaultTabs = registeredTabs.filter((tab) =>+ tab.condition({ topic: this.topic, context: this.context })+ );+ return applyValueTransformer("more-topics-tabs", defaultTabs, {+ currentContext: this.context,+ user: this.currentUser,+ topic: this.topic,+ });+ }++ get selectedTab() {+ return this.tabs.find((tab) => tab === this.preferredTab) || this.tabs[0];+ }++ setup(topic) {+ this.topic = topic;+ let savedId = this.keyValueStore.get(+ `more-topics-preference-${this.context}`+ );+ savedId ||= this.keyValueStore.get("more-topics-list-preference");+ this.preferredTab =+ (savedId && this.tabs.find((tab) => tab.id === savedId)) || null;+ }++ teardown() {+ this.topic = null;+ this.preferredTab = null;+ }++ @action+ selectTab(tab) {+ this.preferredTab = tab;+ this.keyValueStore.set({+ key: `more-topics-preference-${this.context}`,+ value: tab.id,+ });+ }++ @action+ isActiveTab(tab) {+ return tab?.id === this.selectedTab?.id;+ }+}