Skip to content

Commit

Permalink
cover topics with one post and no timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomerobot committed Jan 4, 2024
1 parent b6e398b commit bd76123
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
10 changes: 8 additions & 2 deletions javascripts/discourse/components/toc-timeline.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ export default class TocTimeline extends Component {
return false;
}

// should always show on docs routes
if (this.tocProcessor.isDocs) {
// should always show on docs routes
return true;
}

if (this.args.renderTimeline) {
// single post topics might not have a timeline
// so we should ignore state
if (this.args.topic?.posts_count === 1) {
return true;
}

// timeline state controlled by localStorage
return this.tocProcessor.isTocVisible;
} else {
Expand Down Expand Up @@ -58,7 +64,7 @@ export default class TocTimeline extends Component {
@renderTimeline={{@renderTimeline}}
/>
{{#if @renderTimeline}}
<TocToggle />
<TocToggle @topic={{@topic}} />
{{/if}}
{{/if}}
</div>
Expand Down
27 changes: 17 additions & 10 deletions javascripts/discourse/components/toc-toggle.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ export default class TocToggle extends Component {
@service tocProcessor;

<template>
{{#unless this.tocProcessor.isDocs}}
{{#if this.tocProcessor.hasTOC}}
<DButton
@action={{this.tocProcessor.toggleTocVisibility}}
@icon={{this.toggleIcon}}
@translatedLabel={{i18n (themePrefix this.toggleLabel)}}
@class="btn btn-default timeline-toggle"
/>
{{/if}}
{{/unless}}
{{#if this.shouldShow}}
<DButton
@action={{this.tocProcessor.toggleTocVisibility}}
@icon={{this.toggleIcon}}
@translatedLabel={{i18n (themePrefix this.toggleLabel)}}
@class="btn btn-default timeline-toggle"
/>
{{/if}}
</template>

get shouldShow() {
// docs and topics with 1 post don't need a toggle
if (this.tocProcessor.isDocs || this.args.topic?.posts_count === 1) {
return false;
}

return this.tocProcessor.hasTOC;
}

get toggleLabel() {
if (this.tocProcessor.isTocVisible) {
return "toggle_toc.show_timeline";
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<TocToggle />
<TocToggle @topic={{@outletArgs.model}} />

0 comments on commit bd76123

Please sign in to comment.