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.
This commit is contained in:
Martin Brennan 2025-11-07 10:20:25 +10:00 committed by GitHub
parent 93b37e4069
commit a600db4d06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 83 additions and 68 deletions

View File

@ -3,7 +3,7 @@
# Topics visited grouped by category # Topics visited grouped by category
module DiscourseRewind module DiscourseRewind
module Action module Action
class FavoriteCategories < BaseReport class MostViewedCategories < BaseReport
FakeData = { FakeData = {
data: [ data: [
{ category_id: 1, name: "cats" }, { category_id: 1, name: "cats" },
@ -12,12 +12,12 @@ module DiscourseRewind
{ category_id: 4, name: "management" }, { category_id: 4, name: "management" },
{ category_id: 5, name: "things" }, { category_id: 5, name: "things" },
], ],
identifier: "favorite-categories", identifier: "most-viewed-categories",
} }
def call def call
return FakeData if Rails.env.development? return FakeData if Rails.env.development?
favorite_categories = most_viewed_categories =
TopicViewItem TopicViewItem
.joins(:topic) .joins(:topic)
.joins("INNER JOIN categories ON categories.id = topics.category_id") .joins("INNER JOIN categories ON categories.id = topics.category_id")
@ -30,7 +30,7 @@ module DiscourseRewind
.pluck("categories.id, categories.name") .pluck("categories.id, categories.name")
.map { |category_id, name| { category_id: category_id, name: 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 end
end end

View File

@ -3,7 +3,7 @@
# Topics visited grouped by tag # Topics visited grouped by tag
module DiscourseRewind module DiscourseRewind
module Action module Action
class FavoriteTags < BaseReport class MostViewedTags < BaseReport
FakeData = { FakeData = {
data: [ data: [
{ tag_id: 1, name: "cats" }, { tag_id: 1, name: "cats" },
@ -12,13 +12,13 @@ module DiscourseRewind
{ tag_id: 4, name: "management" }, { tag_id: 4, name: "management" },
{ tag_id: 5, name: "things" }, { tag_id: 5, name: "things" },
], ],
identifier: "favorite-tags", identifier: "most-viewed-tags",
} }
def call def call
return FakeData if Rails.env.development? return FakeData if Rails.env.development?
favorite_tags = most_viewed_tags =
TopicViewItem TopicViewItem
.joins(:topic) .joins(:topic)
.joins("INNER JOIN topic_tags ON topic_tags.topic_id = topics.id") .joins("INNER JOIN topic_tags ON topic_tags.topic_id = topics.id")
@ -32,7 +32,7 @@ module DiscourseRewind
.pluck("tags.id, tags.name") .pluck("tags.id, tags.name")
.map { |tag_id, name| { tag_id: tag_id, name: 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 end
end end

View File

@ -26,8 +26,8 @@ module DiscourseRewind
Action::ReadingTime, Action::ReadingTime,
Action::Reactions, Action::Reactions,
Action::Fbff, Action::Fbff,
Action::FavoriteTags, Action::MostViewedTags,
Action::FavoriteCategories, Action::MostViewedCategories,
Action::BestTopics, Action::BestTopics,
Action::BestPosts, Action::BestPosts,
Action::ActivityCalendar, Action::ActivityCalendar,
@ -62,7 +62,13 @@ module DiscourseRewind
when 12 when 12
current_year current_year
else 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
end end

View File

@ -1,18 +1,18 @@
import { concat } from "@ember/helper"; import { concat } from "@ember/helper";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
const FavoriteCategories = <template> const MostViewedCategories = <template>
{{#if @report.data.length}} {{#if @report.data.length}}
<div class="rewind-report-page -favorite-categories"> <div class="rewind-report-page -most-viewed-categories">
<h2 class="rewind-report-title">{{i18n <h2 class="rewind-report-title">{{i18n
"discourse_rewind.reports.favorite_categories.title" "discourse_rewind.reports.most_viewed_categories.title"
count=@report.data.length count=@report.data.length
}}</h2> }}</h2>
<div class="rewind-report-container"> <div class="rewind-report-container">
{{#each @report.data as |data|}} {{#each @report.data as |data|}}
<a href={{concat "/c/-/" data.category_id}} class="rewind-card"> <a href={{concat "/c/-/" data.category_id}} class="rewind-card">
<p <p
class="favorite-categories__category" class="most-viewed-categories__category"
href={{concat "/c/-/" data.category_id}} href={{concat "/c/-/" data.category_id}}
>{{data.name}}</p> >{{data.name}}</p>
</a> </a>
@ -22,4 +22,4 @@ const FavoriteCategories = <template>
{{/if}} {{/if}}
</template>; </template>;
export default FavoriteCategories; export default MostViewedCategories;

View File

@ -1,18 +1,18 @@
import { concat } from "@ember/helper"; import { concat } from "@ember/helper";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
const FavoriteTags = <template> const MostViewedTags = <template>
{{#if @report.data.length}} {{#if @report.data.length}}
<div class="rewind-report-page -favorite-tags"> <div class="rewind-report-page -most-viewed-tags">
<h2 class="rewind-report-title">{{i18n <h2 class="rewind-report-title">{{i18n
"discourse_rewind.reports.favorite_tags.title" "discourse_rewind.reports.most_viewed_tags.title"
count=@report.data.length count=@report.data.length
}}</h2> }}</h2>
<div class="rewind-report-container"> <div class="rewind-report-container">
{{#each @report.data as |data|}} {{#each @report.data as |data|}}
<a class="rewind-card" href={{concat "/tag/" data.name}}> <a class="rewind-card" href={{concat "/tag/" data.name}}>
<p <p
class="favorite-tags__tag" class="most-viewed-tags__tag"
href={{concat "/tag/" data.name}} href={{concat "/tag/" data.name}}
>#{{data.name}}</p> >#{{data.name}}</p>
</a> </a>
@ -22,4 +22,4 @@ const FavoriteTags = <template>
{{/if}} {{/if}}
</template>; </template>;
export default FavoriteTags; export default MostViewedTags;

View File

@ -11,10 +11,10 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import ActivityCalendar from "discourse/plugins/discourse-rewind/discourse/components/reports/activity-calendar"; import ActivityCalendar from "discourse/plugins/discourse-rewind/discourse/components/reports/activity-calendar";
import BestPosts from "discourse/plugins/discourse-rewind/discourse/components/reports/best-posts"; import BestPosts from "discourse/plugins/discourse-rewind/discourse/components/reports/best-posts";
import BestTopics from "discourse/plugins/discourse-rewind/discourse/components/reports/best-topics"; import BestTopics from "discourse/plugins/discourse-rewind/discourse/components/reports/best-topics";
import FavoriteCategories from "discourse/plugins/discourse-rewind/discourse/components/reports/favorite-categories";
import FavoriteTags from "discourse/plugins/discourse-rewind/discourse/components/reports/favorite-tags";
import FBFF from "discourse/plugins/discourse-rewind/discourse/components/reports/fbff"; import FBFF from "discourse/plugins/discourse-rewind/discourse/components/reports/fbff";
import RewindHeader from "discourse/plugins/discourse-rewind/discourse/components/reports/header"; import RewindHeader from "discourse/plugins/discourse-rewind/discourse/components/reports/header";
import MostViewedCategories from "discourse/plugins/discourse-rewind/discourse/components/reports/most-viewed-categories";
import MostViewedTags from "discourse/plugins/discourse-rewind/discourse/components/reports/most-viewed-tags";
import Reactions from "discourse/plugins/discourse-rewind/discourse/components/reports/reactions"; import Reactions from "discourse/plugins/discourse-rewind/discourse/components/reports/reactions";
import ReadingTime from "discourse/plugins/discourse-rewind/discourse/components/reports/reading-time"; import ReadingTime from "discourse/plugins/discourse-rewind/discourse/components/reports/reading-time";
import TopWords from "discourse/plugins/discourse-rewind/discourse/components/reports/top-words"; import TopWords from "discourse/plugins/discourse-rewind/discourse/components/reports/top-words";
@ -114,12 +114,12 @@ export default class Rewind extends Component {
<BestTopics @report={{report}} /> <BestTopics @report={{report}} />
{{else if (eq report.identifier "activity-calendar")}} {{else if (eq report.identifier "activity-calendar")}}
<ActivityCalendar @report={{report}} /> <ActivityCalendar @report={{report}} />
{{else if (eq report.identifier "favorite-tags")}} {{else if (eq report.identifier "most-viewed-tags")}}
<FavoriteTags @report={{report}} /> <MostViewedTags @report={{report}} />
{{else if (eq report.identifier "reading-time")}} {{else if (eq report.identifier "reading-time")}}
<ReadingTime @report={{report}} /> <ReadingTime @report={{report}} />
{{else if (eq report.identifier "favorite-categories")}} {{else if (eq report.identifier "most-viewed-categories")}}
<FavoriteCategories @report={{report}} /> <MostViewedCategories @report={{report}} />
{{/if}} {{/if}}
</div> </div>
{{/each}} {{/each}}

View File

@ -1,10 +1,12 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import { service } from "@ember/service";
import { TrackedObject } from "@ember-compat/tracked-built-ins"; import { TrackedObject } from "@ember-compat/tracked-built-ins";
import bodyClass from "discourse/helpers/body-class"; import bodyClass from "discourse/helpers/body-class";
import KeyValueStore from "discourse/lib/key-value-store"; import KeyValueStore from "discourse/lib/key-value-store";
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
export default class AvatarDecorator extends Component { export default class AvatarDecorator extends Component {
@service currentUser;
store = new TrackedObject( store = new TrackedObject(
new KeyValueStore("discourse_rewind_" + this.fetchYear) new KeyValueStore("discourse_rewind_" + this.fetchYear)
); );
@ -26,7 +28,7 @@ export default class AvatarDecorator extends Component {
} }
get showDecorator() { get showDecorator() {
return isRewindActive() && !this.dismissed; return this.currentUser?.is_rewind_active && !this.dismissed;
} }
<template> <template>

View File

@ -4,17 +4,20 @@ import { service } from "@ember/service";
import DButton from "discourse/components/d-button"; import DButton from "discourse/components/d-button";
import icon from "discourse/helpers/d-icon"; import icon from "discourse/helpers/d-icon";
import KeyValueStore from "discourse/lib/key-value-store"; import KeyValueStore from "discourse/lib/key-value-store";
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
export default class RewindTab extends Component { export default class RewindCallout extends Component {
@service router; @service router;
@service currentUser;
store = new KeyValueStore("discourse_rewind_" + this.fetchYear); store = new KeyValueStore("discourse_rewind_" + this.fetchYear);
get showCallout() { get showCallout() {
return isRewindActive() && !this.dismissed; return this.currentUser?.is_rewind_active && !this.dismissed;
} }
// We want to show the previous year's rewind in January
// but the current year's rewind in any other month (in
// reality, only December).
get fetchYear() { get fetchYear() {
const currentDate = new Date(); const currentDate = new Date();
const currentMonth = currentDate.getMonth(); const currentMonth = currentDate.getMonth();

View File

@ -1,19 +1,22 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import DNavigationItem from "discourse/components/d-navigation-item"; import DNavigationItem from "discourse/components/d-navigation-item";
import icon from "discourse/helpers/d-icon"; import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
const RewindTab = <template> export default class RewindTab extends Component {
{{#if isRewindActive}} @service currentUser;
<DNavigationItem
@route="userActivity.rewind"
@ariaCurrentContext="subNav"
class="user-nav__activity-rewind"
>
{{icon "repeat"}}
<span>{{i18n "discourse_rewind.title"}}</span>
</DNavigationItem>
{{/if}}
</template>;
export default RewindTab; <template>
{{#if this.currentUser.is_rewind_active}}
<DNavigationItem
@route="userActivity.rewind"
@ariaCurrentContext="subNav"
class="user-nav__activity-rewind"
>
{{icon "repeat"}}
<span>{{i18n "discourse_rewind.title"}}</span>
</DNavigationItem>
{{/if}}
</template>
}

View File

@ -1,5 +0,0 @@
export default function isRewindActive() {
const currentDate = new Date();
const currentMonth = currentDate.getMonth();
return currentMonth === 0 || currentMonth === 11;
}

View File

@ -8,8 +8,8 @@
@import "best-posts"; @import "best-posts";
@import "best-topics"; @import "best-topics";
@import "top-words"; @import "top-words";
@import "favorite-tags"; @import "most-viewed-tags";
@import "favorite-categories"; @import "most-viewed-categories";
@import "fonts"; @import "fonts";
@import "reading-time"; @import "reading-time";
@import "fbff"; @import "fbff";

View File

@ -1,4 +1,4 @@
.-favorite-categories { .-most-viewed-categories {
.rewind-report-container { .rewind-report-container {
display: flex; display: flex;
gap: 0.5em; gap: 0.5em;
@ -16,6 +16,6 @@
} }
} }
.favorite-categories__category { .most-viewed-categories__category {
font-family: var(--pixel-text); font-family: var(--pixel-text);
} }

View File

@ -1,4 +1,4 @@
.-favorite-tags { .-most-viewed-tags {
.rewind-report-container { .rewind-report-container {
display: flex; display: flex;
gap: 0.5em; gap: 0.5em;
@ -16,6 +16,6 @@
} }
} }
.favorite-tags__tag { .most-viewed-tags__tag {
font-family: var(--pixel-text); font-family: var(--pixel-text);
} }

View File

@ -23,14 +23,14 @@ en:
title: Most received reactions in topics title: Most received reactions in topics
fbff: fbff:
title: Your FBFF (Forum Best Friend Forever) title: Your FBFF (Forum Best Friend Forever)
favorite_categories: most_viewed_categories:
title: title:
one: Your favorite category one: Your most viewed category
other: Your %{count} favorite categories other: Your %{count} most viewed categories
favorite_tags: most_viewed_tags:
title: title:
one: Your favorite tag one: Your most viewed tag
other: Your %{count} favorite tags other: Your %{count} most viewed tags
best_topics: best_topics:
title: title:
one: Your best topic one: Your best topic

View File

@ -1 +1,3 @@
en: en:
site_settings:
discourse_rewind_enabled: "Enable Discourse Rewind for a fun end-of-year summary for members' activity in the community."

View File

@ -1,11 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-rewind # name: discourse-rewind
# about: TODO # about: A fun end-of-year summary for members' activity in the community.
# meta_topic_id: TODO # meta_topic_id: https://meta.discourse.org/t/discourse-rewind-2024/348063
# version: 0.0.1 # version: 0.0.1
# authors: Discourse # authors: Discourse
# url: TODO # url: https://github.com/discourse/discourse-rewind
# required_version: 2.7.0 # required_version: 2.7.0
enabled_site_setting :discourse_rewind_enabled enabled_site_setting :discourse_rewind_enabled
@ -25,4 +25,8 @@ end
require_relative "lib/discourse_rewind/engine" require_relative "lib/discourse_rewind/engine"
after_initialize {} after_initialize do
add_to_serializer(:current_user, :is_rewind_active) do
Date.today.month == 1 || Date.today.month == 12
end
end

View File

@ -31,7 +31,7 @@ describe "DiscourseRewind | rewind tab", type: :system do
context "when in november" do context "when in november" do
before { freeze_time DateTime.parse("2022-11-24") } before { freeze_time DateTime.parse("2022-11-24") }
it "doesn show the tab" do it "doesn't show the tab" do
visit("/my/activity") visit("/my/activity")
expect(page).to have_no_selector(".user-nav__activity-rewind") expect(page).to have_no_selector(".user-nav__activity-rewind")