diff --git a/README.md b/README.md index f407564..c750be0 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,8 @@ You can control some features for the provided blocks via parameters. | title | title of the block | varies | string | tag-topics, category-list | | excludedGroupNames | Excludes specified groups | | Group names | top-contributors | | order | Orders the contributors | likes_received | String (likes_received or likes_given) | top-contributors | -| period | Time period for top contributors | yearly | all, yearly, quarterly, monthly, weekly, daily | top-contributors | \ No newline at end of file +| period | Time period for top contributors | yearly | all, yearly, quarterly, monthly, weekly, daily | top-contributors | + +### Blocks from other plugins + +The Discourse Calendar plugin comes with a block called `upcoming-events-list` that you can use in conjunction with this component. You'll want to ensure the desired route is enabled via the `events calendar categories` setting in the Calendar plugin settings. The block params use this [syntax](https://momentjs.com/docs/#/displaying/format/), for example `MMMM D, YYYY`. diff --git a/about.json b/about.json index 169b2e3..e5c09b3 100644 --- a/about.json +++ b/about.json @@ -5,7 +5,7 @@ "license_url": "https://github.com/discourse/discourse-right-sidebar-blocks/blob/main/LICENSE", "about_url": "https://meta.discourse.org/t/right-sidebar-blocks/231067", "learn_more": "TODO", - "theme_version": "0.0.1", + "theme_version": "0.0.2", "minimum_discourse_version": null, "maximum_discourse_version": null, "assets": {}, diff --git a/javascripts/connectors/before-list-area/tc-right-sidebar.js b/javascripts/connectors/before-list-area/tc-right-sidebar.js index a3382c9..216eb9b 100644 --- a/javascripts/connectors/before-list-area/tc-right-sidebar.js +++ b/javascripts/connectors/before-list-area/tc-right-sidebar.js @@ -8,20 +8,37 @@ export default { @discourseComputed( "router.currentRouteName", + "router.currentRoute.attributes.category", "router.currentRoute.attributes.category.slug", "router.currentRoute.attributes.tag.id" ) - showSidebar(currentRouteName, categorySlug, tagId) { + showSidebar(currentRouteName, category, categorySlug, tagId) { if (this.site.mobileView) { return false; } if (settings.show_in_routes !== "") { const selectedRoutes = settings.show_in_routes.split("|"); + let subcategory = null; + let parentCategory = null; + + // check if current page is subcategory + // -- is category + // -- does not have children itself + // -- has a parent category + if ( + !!this.category && + !this.category.has_children && + !!this.category.parent_category_id + ) { + subcategory = categorySlug; + parentCategory = category.ancestors[0].slug; + } if ( selectedRoutes.includes(currentRouteName) || selectedRoutes.includes(`c/${categorySlug}`) || + selectedRoutes.includes(`c/${parentCategory}/${subcategory}`) || selectedRoutes.includes(`tag/${tagId}`) ) { return true; diff --git a/test/acceptance/right-sidebar-test.js b/test/acceptance/right-sidebar-test.js index ff40175..1fc4fd8 100644 --- a/test/acceptance/right-sidebar-test.js +++ b/test/acceptance/right-sidebar-test.js @@ -26,13 +26,29 @@ acceptance("Right Sidebar - custom routes", function (needs) { needs.hooks.beforeEach(() => { settings.show_in_routes = - "discovery.categories|discovery.top|c/bug|tag/important"; + "discovery.categories|discovery.top|c/bug|c/bug/foo|tag/important"; }); needs.hooks.afterEach(() => { settings.blocks = "[]"; }); + needs.site({ + categories: [ + { + id: 1, + name: "bug", + slug: "bug", + }, + { + id: 2, + name: "foo", + slug: "foo", + parent_category_id: 1, + }, + ], + }); + needs.pretender((server, helper) => { server.get(`/c/bug/1/l/latest.json`, () => { return helper.response( @@ -40,6 +56,12 @@ acceptance("Right Sidebar - custom routes", function (needs) { ); }); + server.get(`/c/bug/foo/2/l/latest.json`, () => { + return helper.response( + cloneJSON(discoveryFixture["/c/bug/1/l/latest.json"]) + ); + }); + server.get(`/tag/important/l/latest.json`, () => { return helper.response( cloneJSON(discoveryFixture["/tag/important/l/latest.json"]) @@ -81,6 +103,15 @@ acceptance("Right Sidebar - custom routes", function (needs) { ); }); + test("Viewing the foo subcategory", async function (assert) { + await visit("/c/bug/foo/2"); + + assert.ok( + visible(".tc-right-sidebar"), + "sidebar present under the foo subcategory" + ); + }); + test("Viewing the important tag", async function (assert) { await visit("/tag/important");