Skip to content

Commit a600db4

Browse files
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.
1 parent 93b37e4 commit a600db4

File tree

18 files changed

+83
-68
lines changed

18 files changed

+83
-68
lines changed

app/services/discourse_rewind/action/favorite_categories.rb renamed to app/services/discourse_rewind/action/most_viewed_categories.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Topics visited grouped by category
44
module DiscourseRewind
55
module Action
6-
class FavoriteCategories < BaseReport
6+
class MostViewedCategories < BaseReport
77
FakeData = {
88
data: [
99
{ category_id: 1, name: "cats" },
@@ -12,12 +12,12 @@ class FavoriteCategories < BaseReport
1212
{ category_id: 4, name: "management" },
1313
{ category_id: 5, name: "things" },
1414
],
15-
identifier: "favorite-categories",
15+
identifier: "most-viewed-categories",
1616
}
1717
def call
1818
return FakeData if Rails.env.development?
1919

20-
favorite_categories =
20+
most_viewed_categories =
2121
TopicViewItem
2222
.joins(:topic)
2323
.joins("INNER JOIN categories ON categories.id = topics.category_id")
@@ -30,7 +30,7 @@ def call
3030
.pluck("categories.id, categories.name")
3131
.map { |category_id, name| { category_id: category_id, name: name } }
3232

33-
{ data: favorite_categories, identifier: "favorite-categories" }
33+
{ data: most_viewed_categories, identifier: "most-viewed-categories" }
3434
end
3535
end
3636
end

app/services/discourse_rewind/action/favorite_tags.rb renamed to app/services/discourse_rewind/action/most_viewed_tags.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Topics visited grouped by tag
44
module DiscourseRewind
55
module Action
6-
class FavoriteTags < BaseReport
6+
class MostViewedTags < BaseReport
77
FakeData = {
88
data: [
99
{ tag_id: 1, name: "cats" },
@@ -12,13 +12,13 @@ class FavoriteTags < BaseReport
1212
{ tag_id: 4, name: "management" },
1313
{ tag_id: 5, name: "things" },
1414
],
15-
identifier: "favorite-tags",
15+
identifier: "most-viewed-tags",
1616
}
1717

1818
def call
1919
return FakeData if Rails.env.development?
2020

21-
favorite_tags =
21+
most_viewed_tags =
2222
TopicViewItem
2323
.joins(:topic)
2424
.joins("INNER JOIN topic_tags ON topic_tags.topic_id = topics.id")
@@ -32,7 +32,7 @@ def call
3232
.pluck("tags.id, tags.name")
3333
.map { |tag_id, name| { tag_id: tag_id, name: name } }
3434

35-
{ data: favorite_tags, identifier: "favorite-tags" }
35+
{ data: most_viewed_tags, identifier: "most-viewed-tags" }
3636
end
3737
end
3838
end

app/services/discourse_rewind/fetch_reports.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class FetchReports
2626
Action::ReadingTime,
2727
Action::Reactions,
2828
Action::Fbff,
29-
Action::FavoriteTags,
30-
Action::FavoriteCategories,
29+
Action::MostViewedTags,
30+
Action::MostViewedCategories,
3131
Action::BestTopics,
3232
Action::BestPosts,
3333
Action::ActivityCalendar,
@@ -62,7 +62,13 @@ def fetch_year
6262
when 12
6363
current_year
6464
else
65-
false
65+
# Otherwise it's impossible to test in browser unless you're
66+
# in December or January
67+
if Rails.env.development?
68+
current_year
69+
else
70+
false
71+
end
6672
end
6773
end
6874

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { concat } from "@ember/helper";
22
import { i18n } from "discourse-i18n";
33

4-
const FavoriteCategories = <template>
4+
const MostViewedCategories = <template>
55
{{#if @report.data.length}}
6-
<div class="rewind-report-page -favorite-categories">
6+
<div class="rewind-report-page -most-viewed-categories">
77
<h2 class="rewind-report-title">{{i18n
8-
"discourse_rewind.reports.favorite_categories.title"
8+
"discourse_rewind.reports.most_viewed_categories.title"
99
count=@report.data.length
1010
}}</h2>
1111
<div class="rewind-report-container">
1212
{{#each @report.data as |data|}}
1313
<a href={{concat "/c/-/" data.category_id}} class="rewind-card">
1414
<p
15-
class="favorite-categories__category"
15+
class="most-viewed-categories__category"
1616
href={{concat "/c/-/" data.category_id}}
1717
>{{data.name}}</p>
1818
</a>
@@ -22,4 +22,4 @@ const FavoriteCategories = <template>
2222
{{/if}}
2323
</template>;
2424

25-
export default FavoriteCategories;
25+
export default MostViewedCategories;
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { concat } from "@ember/helper";
22
import { i18n } from "discourse-i18n";
33

4-
const FavoriteTags = <template>
4+
const MostViewedTags = <template>
55
{{#if @report.data.length}}
6-
<div class="rewind-report-page -favorite-tags">
6+
<div class="rewind-report-page -most-viewed-tags">
77
<h2 class="rewind-report-title">{{i18n
8-
"discourse_rewind.reports.favorite_tags.title"
8+
"discourse_rewind.reports.most_viewed_tags.title"
99
count=@report.data.length
1010
}}</h2>
1111
<div class="rewind-report-container">
1212
{{#each @report.data as |data|}}
1313
<a class="rewind-card" href={{concat "/tag/" data.name}}>
1414
<p
15-
class="favorite-tags__tag"
15+
class="most-viewed-tags__tag"
1616
href={{concat "/tag/" data.name}}
1717
>#{{data.name}}</p>
1818
</a>
@@ -22,4 +22,4 @@ const FavoriteTags = <template>
2222
{{/if}}
2323
</template>;
2424

25-
export default FavoriteTags;
25+
export default MostViewedTags;

assets/javascripts/discourse/components/rewind.gjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
1111
import ActivityCalendar from "discourse/plugins/discourse-rewind/discourse/components/reports/activity-calendar";
1212
import BestPosts from "discourse/plugins/discourse-rewind/discourse/components/reports/best-posts";
1313
import BestTopics from "discourse/plugins/discourse-rewind/discourse/components/reports/best-topics";
14-
import FavoriteCategories from "discourse/plugins/discourse-rewind/discourse/components/reports/favorite-categories";
15-
import FavoriteTags from "discourse/plugins/discourse-rewind/discourse/components/reports/favorite-tags";
1614
import FBFF from "discourse/plugins/discourse-rewind/discourse/components/reports/fbff";
1715
import RewindHeader from "discourse/plugins/discourse-rewind/discourse/components/reports/header";
16+
import MostViewedCategories from "discourse/plugins/discourse-rewind/discourse/components/reports/most-viewed-categories";
17+
import MostViewedTags from "discourse/plugins/discourse-rewind/discourse/components/reports/most-viewed-tags";
1818
import Reactions from "discourse/plugins/discourse-rewind/discourse/components/reports/reactions";
1919
import ReadingTime from "discourse/plugins/discourse-rewind/discourse/components/reports/reading-time";
2020
import TopWords from "discourse/plugins/discourse-rewind/discourse/components/reports/top-words";
@@ -114,12 +114,12 @@ export default class Rewind extends Component {
114114
<BestTopics @report={{report}} />
115115
{{else if (eq report.identifier "activity-calendar")}}
116116
<ActivityCalendar @report={{report}} />
117-
{{else if (eq report.identifier "favorite-tags")}}
118-
<FavoriteTags @report={{report}} />
117+
{{else if (eq report.identifier "most-viewed-tags")}}
118+
<MostViewedTags @report={{report}} />
119119
{{else if (eq report.identifier "reading-time")}}
120120
<ReadingTime @report={{report}} />
121-
{{else if (eq report.identifier "favorite-categories")}}
122-
<FavoriteCategories @report={{report}} />
121+
{{else if (eq report.identifier "most-viewed-categories")}}
122+
<MostViewedCategories @report={{report}} />
123123
{{/if}}
124124
</div>
125125
{{/each}}

assets/javascripts/discourse/connectors/after-header-panel/rewind-decoration.gjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
23
import { TrackedObject } from "@ember-compat/tracked-built-ins";
34
import bodyClass from "discourse/helpers/body-class";
45
import KeyValueStore from "discourse/lib/key-value-store";
5-
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
66

77
export default class AvatarDecorator extends Component {
8+
@service currentUser;
9+
810
store = new TrackedObject(
911
new KeyValueStore("discourse_rewind_" + this.fetchYear)
1012
);
@@ -26,7 +28,7 @@ export default class AvatarDecorator extends Component {
2628
}
2729

2830
get showDecorator() {
29-
return isRewindActive() && !this.dismissed;
31+
return this.currentUser?.is_rewind_active && !this.dismissed;
3032
}
3133

3234
<template>

assets/javascripts/discourse/connectors/before-panel-body/rewind-callout.gjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ import { service } from "@ember/service";
44
import DButton from "discourse/components/d-button";
55
import icon from "discourse/helpers/d-icon";
66
import KeyValueStore from "discourse/lib/key-value-store";
7-
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
87

9-
export default class RewindTab extends Component {
8+
export default class RewindCallout extends Component {
109
@service router;
10+
@service currentUser;
1111

1212
store = new KeyValueStore("discourse_rewind_" + this.fetchYear);
1313

1414
get showCallout() {
15-
return isRewindActive() && !this.dismissed;
15+
return this.currentUser?.is_rewind_active && !this.dismissed;
1616
}
1717

18+
// We want to show the previous year's rewind in January
19+
// but the current year's rewind in any other month (in
20+
// reality, only December).
1821
get fetchYear() {
1922
const currentDate = new Date();
2023
const currentMonth = currentDate.getMonth();
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
13
import DNavigationItem from "discourse/components/d-navigation-item";
24
import icon from "discourse/helpers/d-icon";
35
import { i18n } from "discourse-i18n";
4-
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
56

6-
const RewindTab = <template>
7-
{{#if isRewindActive}}
8-
<DNavigationItem
9-
@route="userActivity.rewind"
10-
@ariaCurrentContext="subNav"
11-
class="user-nav__activity-rewind"
12-
>
13-
{{icon "repeat"}}
14-
<span>{{i18n "discourse_rewind.title"}}</span>
15-
</DNavigationItem>
16-
{{/if}}
17-
</template>;
7+
export default class RewindTab extends Component {
8+
@service currentUser;
189

19-
export default RewindTab;
10+
<template>
11+
{{#if this.currentUser.is_rewind_active}}
12+
<DNavigationItem
13+
@route="userActivity.rewind"
14+
@ariaCurrentContext="subNav"
15+
class="user-nav__activity-rewind"
16+
>
17+
{{icon "repeat"}}
18+
<span>{{i18n "discourse_rewind.title"}}</span>
19+
</DNavigationItem>
20+
{{/if}}
21+
</template>
22+
}

assets/javascripts/discourse/lib/is-rewind-active.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)