From 8881ae4af4da36e478dd5309ebda81c791790f68 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 28 Jan 2021 11:48:51 +0100 Subject: [PATCH] DEV: Remove dead code (`latestTopicOnly`) (#11833) Background: I wanted to see `categories.latest_by` translation in context in a live app but couldn't find it, so I traced it throughout the code. My step-by-step reasoning for the removal is: 1. `categories-only` does not use `latestTopicOnly`, so there's no need to call it with that argument 2. `parent-category-row` is never called with `latestTopicOnly` argument, so the reference to that arg can be removed from its template 3. after that, `featured-topic` is now no longer ever called with `latestTopicOnly` argument (except in the `ghost` theme, but that's because its override of `categories-only` template https://github.com/discourse/ghost/blob/4e2fba963c5f3fa6159c1a14d45ac9e82ce7b214/common/header.html#L119 is based on the old version of that template from core), so it seems safe to remove it there too (`categories.latest_by` i18n string is also no longer needed) 4. then, nothing is using `latestTopicOnly` anymore so it can be removed from `categories` hbs/js I checked in each step that there are no plugins or themes (in all-the-plugins/all-the-themes) using those properties/arguments/strings. --- .../discourse/app/controllers/discovery/categories.js | 9 --------- .../components/categories-with-featured-topics.hbs | 1 - .../app/templates/components/featured-topic.hbs | 9 +-------- .../app/templates/components/parent-category-row.hbs | 2 +- .../discourse/app/templates/discovery/categories.hbs | 1 - .../components/categories-with-featured-topics.hbs | 1 - .../app/templates/mobile/discovery/categories.hbs | 1 - config/locales/client.en.yml | 1 - 8 files changed, 2 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/discovery/categories.js b/app/assets/javascripts/discourse/app/controllers/discovery/categories.js index 01879ddc2e..b286fd4fda 100644 --- a/app/assets/javascripts/discourse/app/controllers/discovery/categories.js +++ b/app/assets/javascripts/discourse/app/controllers/discovery/categories.js @@ -19,15 +19,6 @@ export default DiscoveryController.extend({ canEdit: reads("currentUser.staff"), - @discourseComputed("model.categories.[].featuredTopics.length") - latestTopicOnly() { - return ( - this.get("model.categories").find( - (c) => c.get("featuredTopics.length") > 1 - ) === undefined - ); - }, - @discourseComputed("model.parentCategory") categoryPageStyle(parentCategory) { let style = this.site.mobileView diff --git a/app/assets/javascripts/discourse/app/templates/components/categories-with-featured-topics.hbs b/app/assets/javascripts/discourse/app/templates/components/categories-with-featured-topics.hbs index 9243d15028..b62e4a8fb5 100644 --- a/app/assets/javascripts/discourse/app/templates/components/categories-with-featured-topics.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/categories-with-featured-topics.hbs @@ -1,3 +1,2 @@ {{categories-only categories=categories - latestTopicOnly=latestTopicOnly showTopics="true"}} diff --git a/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs b/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs index 937d05c1d5..c6a04a2d69 100644 --- a/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs @@ -2,11 +2,4 @@ {{html-safe topic.fancyTitle}} {{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}} -{{#if latestTopicOnly}} -
- {{i18n "categories.latest_by"}} {{topic.last_poster.username}} - {{format-age topic.last_posted_at}} -
-{{else}} - {{format-age topic.last_posted_at}} -{{/if}} +{{format-age topic.last_posted_at}} diff --git a/app/assets/javascripts/discourse/app/templates/components/parent-category-row.hbs b/app/assets/javascripts/discourse/app/templates/components/parent-category-row.hbs index 58e4b1a693..dbf5cc2922 100644 --- a/app/assets/javascripts/discourse/app/templates/components/parent-category-row.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/parent-category-row.hbs @@ -32,7 +32,7 @@ {{#if showTopics}} {{#each category.featuredTopics as |t|}} - {{featured-topic topic=t latestTopicOnly=latestTopicOnly}} + {{featured-topic topic=t}} {{/each}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/app/templates/discovery/categories.hbs index 6a5c91b8b8..282c608b75 100644 --- a/app/assets/javascripts/discourse/app/templates/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/app/templates/discovery/categories.hbs @@ -1,6 +1,5 @@ {{#discovery-categories refresh=(action "refresh")}} {{component categoryPageStyle categories=model.categories - latestTopicOnly=latestTopicOnly topics=model.topics}} {{/discovery-categories}} diff --git a/app/assets/javascripts/discourse/app/templates/mobile/components/categories-with-featured-topics.hbs b/app/assets/javascripts/discourse/app/templates/mobile/components/categories-with-featured-topics.hbs index 9243d15028..b62e4a8fb5 100644 --- a/app/assets/javascripts/discourse/app/templates/mobile/components/categories-with-featured-topics.hbs +++ b/app/assets/javascripts/discourse/app/templates/mobile/components/categories-with-featured-topics.hbs @@ -1,3 +1,2 @@ {{categories-only categories=categories - latestTopicOnly=latestTopicOnly showTopics="true"}} diff --git a/app/assets/javascripts/discourse/app/templates/mobile/discovery/categories.hbs b/app/assets/javascripts/discourse/app/templates/mobile/discovery/categories.hbs index 6a5c91b8b8..282c608b75 100644 --- a/app/assets/javascripts/discourse/app/templates/mobile/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/app/templates/mobile/discovery/categories.hbs @@ -1,6 +1,5 @@ {{#discovery-categories refresh=(action "refresh")}} {{component categoryPageStyle categories=model.categories - latestTopicOnly=latestTopicOnly topics=model.topics}} {{/discovery-categories}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 30f998f7b3..e3d88511e1 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -838,7 +838,6 @@ en: posts: "Posts" topics: "Topics" latest: "Latest" - latest_by: "latest by" toggle_ordering: "toggle ordering control" subcategories: "Subcategories" muted: "Muted categories"