Separare gli Argomenti Fissati

Ciao Terise,

Ho esaminato il tuo codice e ci sei quasi!

Ecco alcuni feedback:

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/topic-list/list.gjs#L126-L136

Ciò significa che questo dovrebbe essere:

export default class PinnedTopicBody extends Component {
  get pinnedTopics() {
    return this.outletArgs.topics.filter((t) => t.get("pinned"));
  }
}
 

e il template:

{{#if this.pinnedTopics}}
  <tbody>
    {{#each this.pinnedTopics as |topic|}}
      <TopicListItem
        @topic={{topic}}
        @bulkSelectEnabled={{@outletArgs.bulkSelectEnabled}}
        @lastVisitedTopic={{@outletArgs.lastVisitedTopic}}
        @selected={{@outletArgs.selected}}
        @hideCategory={{@outletArgs.hideCategory}}
        @showPosters={{true}}
      />
    {{/each}}
    <tr class="table-break">
      <td colspan="10">&nbsp;</td>
    </tr>
  </tbody>
{{/if}}

Genera un div wrapper con un ID univoco e rovina il CSS. Tuttavia, è necessario se vuoi associare azioni all’elemento.

Puoi usare tagName e classNames per personalizzare il wrapper.

import { classNames, tagName } from "@ember-decorators/component";
 
@tagName("tbody")
@classNames("pinned-topics")
export default class PinnedTopicBody extends Component {
  ...
}
{{#if this.pinnedTopics}}
  {{#each this.pinnedTopics as |topic|}}
    ...
  {{/each}}
  <tr class="table-break">
    <td colspan="10">&nbsp;</td>
  </tr>
{{/if}}

(se sai che non farai nulla sull’elemento, puoi mantenere il tbody nel template e usare tagName("")).

Quindi, ottieni questo:

Non l’ho esaminato a fondo per vedere se c’era un modo migliore.
Volevo solo aiutarti a far funzionare il tuo codice! :smile: