-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR: Update from widget to glimmer component (#8)
- Loading branch information
1 parent
2960a74
commit 28fa1c6
Showing
8 changed files
with
114 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "discourse-tag-banners", | ||
"name": "Tag Banners", | ||
"component": true, | ||
"about_url": "", | ||
"license_url": "" | ||
"about_url": "https://meta.discourse.org/t/tag-banners/124240", | ||
"license_url": "https://github.com/discourse/discourse-tag-banners/blob/main/LICENSE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
javascripts/discourse/components/discourse-tag-banners.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{{#if (not (and this.site.mobileView (not (theme-setting "show_on_mobile"))))}} | ||
{{#if this.shouldRender}} | ||
<div | ||
{{did-insert this.getTagInfo}} | ||
{{did-update this.getTagInfo this.shouldRender}} | ||
{{will-destroy this.resetTag}} | ||
class={{concat-class | ||
"tag-title-header" | ||
(concat "tag-banner-" this.formattedTagName) | ||
this.additionalClass | ||
}} | ||
> | ||
<div class="tag-title-contents"> | ||
<h1> | ||
<span>{{this.formattedTagName}}</span> | ||
{{#if this.formattedAdditionalTagNames}} | ||
& | ||
{{this.formattedAdditionalTagNames}} | ||
{{/if}} | ||
</h1> | ||
{{#unless this.isIntersection}} | ||
{{! hide descriptions on tag intersections}} | ||
{{#if (theme-setting "show_tag_description")}} | ||
<p>{{this.tag.description}}</p> | ||
{{/if}} | ||
{{/unless}} | ||
</div> | ||
</div> | ||
{{/if}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
|
||
export default class DiscourseTagBanners extends Component { | ||
@service store; | ||
@service router; | ||
@service site; | ||
@tracked tag = null; | ||
@tracked keepDuringLoadingRoute = false; | ||
@tracked isIntersection = false; | ||
|
||
#formatTagName(tagName = "") { | ||
// for intersections: tag1/tag2 => tag1 & tag2 | ||
tagName = tagName.replace(/\//g, " & "); | ||
|
||
if (settings.remove_tag_hyphen) { | ||
tagName = tagName.replace(/-/g, " "); | ||
} | ||
if (settings.remove_tag_underscore) { | ||
tagName = tagName.replace(/_/g, " "); | ||
} | ||
return tagName; | ||
} | ||
|
||
get currentRouteParams() { | ||
return this.router?.currentRoute?.params; | ||
} | ||
|
||
get shouldRender() { | ||
return ( | ||
(this.currentRouteParams.tag_id !== "none" && | ||
this.currentRouteParams?.tag_id) || | ||
(this.keepDuringLoadingRoute && | ||
this.router.currentRoute.name.includes("loading")) | ||
); | ||
} | ||
|
||
get formattedTagName() { | ||
return this.#formatTagName(this.tag?.name); | ||
} | ||
|
||
get formattedAdditionalTagNames() { | ||
const additionalTags = this.currentRouteParams.additional_tags; | ||
return additionalTags ? this.#formatTagName(additionalTags) : ""; | ||
} | ||
|
||
get additionalClass() { | ||
if (this.formattedAdditionalTagNames === "") { | ||
return "single-tag"; | ||
} | ||
|
||
let tagList = this.formattedAdditionalTagNames.split(" & "); | ||
return tagList.map((e) => `tag-banner-${e}`).join(" "); | ||
} | ||
|
||
@action | ||
async getTagInfo() { | ||
const tag = this.currentRouteParams?.tag_id; | ||
if (tag) { | ||
const result = await this.store.find("tag-info", tag); | ||
this.tag = result; | ||
this.isIntersection = this.currentRouteParams.additional_tags; | ||
this.keepDuringLoadingRoute = true; | ||
} else { | ||
if (!this.router.currentRoute.name.includes("loading")) { | ||
this.keepDuringLoadingRoute = false; | ||
} | ||
} | ||
} | ||
|
||
@action | ||
resetTag() { | ||
this.keepDuringLoadingRoute = false; | ||
this.tag = null; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
javascripts/discourse/connectors/above-site-header/tag-header-widget.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{#if (theme-setting "show_above_site_header")}} | ||
{{mount-widget widget="tag-header-widget"}} | ||
<DiscourseTagBanners /> | ||
{{/if}} |
2 changes: 1 addition & 1 deletion
2
javascripts/discourse/connectors/below-site-header/tag-header-widget.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{#if (theme-setting "show_below_site_header")}} | ||
{{mount-widget widget="tag-header-widget"}} | ||
<DiscourseTagBanners /> | ||
{{/if}} |
15 changes: 0 additions & 15 deletions
15
javascripts/discourse/initializers/discourse-tag-banners.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.