From a600db4d06a1747ac38a2fe6f0147f4cd116d301 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 7 Nov 2025 10:20:25 +1000 Subject: [PATCH] FIX: Rename Favorite Tags/Categories to Most Viewed Tags/Categories and isRewindActive fixes (#27) This was confusing people last year, most people assumed it meant the tags they used the most / categories they posted in the most. This should clear things up. Also removes the `isRewindActive` function in favour of `is_rewind_active` on the current user, since then we only have one place to check this, and it makes testing easier since we don't have to mock browser time. Finally it moves the route for rewind in the UI to the new route path format. --- ...ategories.rb => most_viewed_categories.rb} | 8 ++--- .../{favorite_tags.rb => most_viewed_tags.rb} | 8 ++--- .../discourse_rewind/fetch_reports.rb | 12 +++++-- ...egories.gjs => most-viewed-categories.gjs} | 10 +++--- ...favorite-tags.gjs => most-viewed-tags.gjs} | 10 +++--- .../discourse/components/rewind.gjs | 12 +++---- .../after-header-panel/rewind-decoration.gjs | 6 ++-- .../before-panel-body/rewind-callout.gjs | 9 ++++-- .../user-activity-bottom/rewind-tab.gjs | 31 ++++++++++--------- .../discourse/lib/is-rewind-active.js | 5 --- .../rewind.js} | 0 assets/stylesheets/common/_index.scss | 4 +-- ...ories.scss => most-viewed-categories.scss} | 4 +-- ...vorite-tags.scss => most-viewed-tags.scss} | 4 +-- config/locales/client.en.yml | 12 +++---- config/locales/server.en.yml | 2 ++ plugin.rb | 12 ++++--- spec/system/rewind_tab_spec.rb | 2 +- 18 files changed, 83 insertions(+), 68 deletions(-) rename app/services/discourse_rewind/action/{favorite_categories.rb => most_viewed_categories.rb} (83%) rename app/services/discourse_rewind/action/{favorite_tags.rb => most_viewed_tags.rb} (85%) rename assets/javascripts/discourse/components/reports/{favorite-categories.gjs => most-viewed-categories.gjs} (67%) rename assets/javascripts/discourse/components/reports/{favorite-tags.gjs => most-viewed-tags.gjs} (70%) delete mode 100644 assets/javascripts/discourse/lib/is-rewind-active.js rename assets/javascripts/discourse/routes/{user-activity-rewind.js => user-activity/rewind.js} (100%) rename assets/stylesheets/common/{favorite-categories.scss => most-viewed-categories.scss} (82%) rename assets/stylesheets/common/{favorite-tags.scss => most-viewed-tags.scss} (86%) diff --git a/app/services/discourse_rewind/action/favorite_categories.rb b/app/services/discourse_rewind/action/most_viewed_categories.rb similarity index 83% rename from app/services/discourse_rewind/action/favorite_categories.rb rename to app/services/discourse_rewind/action/most_viewed_categories.rb index 641ae18..6aa6ebe 100644 --- a/app/services/discourse_rewind/action/favorite_categories.rb +++ b/app/services/discourse_rewind/action/most_viewed_categories.rb @@ -3,7 +3,7 @@ # Topics visited grouped by category module DiscourseRewind module Action - class FavoriteCategories < BaseReport + class MostViewedCategories < BaseReport FakeData = { data: [ { category_id: 1, name: "cats" }, @@ -12,12 +12,12 @@ module DiscourseRewind { category_id: 4, name: "management" }, { category_id: 5, name: "things" }, ], - identifier: "favorite-categories", + identifier: "most-viewed-categories", } def call return FakeData if Rails.env.development? - favorite_categories = + most_viewed_categories = TopicViewItem .joins(:topic) .joins("INNER JOIN categories ON categories.id = topics.category_id") @@ -30,7 +30,7 @@ module DiscourseRewind .pluck("categories.id, categories.name") .map { |category_id, name| { category_id: category_id, name: name } } - { data: favorite_categories, identifier: "favorite-categories" } + { data: most_viewed_categories, identifier: "most-viewed-categories" } end end end diff --git a/app/services/discourse_rewind/action/favorite_tags.rb b/app/services/discourse_rewind/action/most_viewed_tags.rb similarity index 85% rename from app/services/discourse_rewind/action/favorite_tags.rb rename to app/services/discourse_rewind/action/most_viewed_tags.rb index 112268d..a11661e 100644 --- a/app/services/discourse_rewind/action/favorite_tags.rb +++ b/app/services/discourse_rewind/action/most_viewed_tags.rb @@ -3,7 +3,7 @@ # Topics visited grouped by tag module DiscourseRewind module Action - class FavoriteTags < BaseReport + class MostViewedTags < BaseReport FakeData = { data: [ { tag_id: 1, name: "cats" }, @@ -12,13 +12,13 @@ module DiscourseRewind { tag_id: 4, name: "management" }, { tag_id: 5, name: "things" }, ], - identifier: "favorite-tags", + identifier: "most-viewed-tags", } def call return FakeData if Rails.env.development? - favorite_tags = + most_viewed_tags = TopicViewItem .joins(:topic) .joins("INNER JOIN topic_tags ON topic_tags.topic_id = topics.id") @@ -32,7 +32,7 @@ module DiscourseRewind .pluck("tags.id, tags.name") .map { |tag_id, name| { tag_id: tag_id, name: name } } - { data: favorite_tags, identifier: "favorite-tags" } + { data: most_viewed_tags, identifier: "most-viewed-tags" } end end end diff --git a/app/services/discourse_rewind/fetch_reports.rb b/app/services/discourse_rewind/fetch_reports.rb index a685231..c959a24 100644 --- a/app/services/discourse_rewind/fetch_reports.rb +++ b/app/services/discourse_rewind/fetch_reports.rb @@ -26,8 +26,8 @@ module DiscourseRewind Action::ReadingTime, Action::Reactions, Action::Fbff, - Action::FavoriteTags, - Action::FavoriteCategories, + Action::MostViewedTags, + Action::MostViewedCategories, Action::BestTopics, Action::BestPosts, Action::ActivityCalendar, @@ -62,7 +62,13 @@ module DiscourseRewind when 12 current_year else - false + # Otherwise it's impossible to test in browser unless you're + # in December or January + if Rails.env.development? + current_year + else + false + end end end diff --git a/assets/javascripts/discourse/components/reports/favorite-categories.gjs b/assets/javascripts/discourse/components/reports/most-viewed-categories.gjs similarity index 67% rename from assets/javascripts/discourse/components/reports/favorite-categories.gjs rename to assets/javascripts/discourse/components/reports/most-viewed-categories.gjs index 47bb41f..5d72a85 100644 --- a/assets/javascripts/discourse/components/reports/favorite-categories.gjs +++ b/assets/javascripts/discourse/components/reports/most-viewed-categories.gjs @@ -1,18 +1,18 @@ import { concat } from "@ember/helper"; import { i18n } from "discourse-i18n"; -const FavoriteCategories =