mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-12-11 10:05:32 +00:00
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:
parent
93b37e4069
commit
a600db4d06
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import { concat } from "@ember/helper";
|
||||
import { i18n } from "discourse-i18n";
|
||||
|
||||
const FavoriteCategories = <template>
|
||||
const MostViewedCategories = <template>
|
||||
{{#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
|
||||
"discourse_rewind.reports.favorite_categories.title"
|
||||
"discourse_rewind.reports.most_viewed_categories.title"
|
||||
count=@report.data.length
|
||||
}}</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{#each @report.data as |data|}}
|
||||
<a href={{concat "/c/-/" data.category_id}} class="rewind-card">
|
||||
<p
|
||||
class="favorite-categories__category"
|
||||
class="most-viewed-categories__category"
|
||||
href={{concat "/c/-/" data.category_id}}
|
||||
>{{data.name}}</p>
|
||||
</a>
|
||||
@ -22,4 +22,4 @@ const FavoriteCategories = <template>
|
||||
{{/if}}
|
||||
</template>;
|
||||
|
||||
export default FavoriteCategories;
|
||||
export default MostViewedCategories;
|
||||
@ -1,18 +1,18 @@
|
||||
import { concat } from "@ember/helper";
|
||||
import { i18n } from "discourse-i18n";
|
||||
|
||||
const FavoriteTags = <template>
|
||||
const MostViewedTags = <template>
|
||||
{{#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
|
||||
"discourse_rewind.reports.favorite_tags.title"
|
||||
"discourse_rewind.reports.most_viewed_tags.title"
|
||||
count=@report.data.length
|
||||
}}</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{#each @report.data as |data|}}
|
||||
<a class="rewind-card" href={{concat "/tag/" data.name}}>
|
||||
<p
|
||||
class="favorite-tags__tag"
|
||||
class="most-viewed-tags__tag"
|
||||
href={{concat "/tag/" data.name}}
|
||||
>#{{data.name}}</p>
|
||||
</a>
|
||||
@ -22,4 +22,4 @@ const FavoriteTags = <template>
|
||||
{{/if}}
|
||||
</template>;
|
||||
|
||||
export default FavoriteTags;
|
||||
export default MostViewedTags;
|
||||
@ -11,10 +11,10 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
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 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 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 ReadingTime from "discourse/plugins/discourse-rewind/discourse/components/reports/reading-time";
|
||||
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}} />
|
||||
{{else if (eq report.identifier "activity-calendar")}}
|
||||
<ActivityCalendar @report={{report}} />
|
||||
{{else if (eq report.identifier "favorite-tags")}}
|
||||
<FavoriteTags @report={{report}} />
|
||||
{{else if (eq report.identifier "most-viewed-tags")}}
|
||||
<MostViewedTags @report={{report}} />
|
||||
{{else if (eq report.identifier "reading-time")}}
|
||||
<ReadingTime @report={{report}} />
|
||||
{{else if (eq report.identifier "favorite-categories")}}
|
||||
<FavoriteCategories @report={{report}} />
|
||||
{{else if (eq report.identifier "most-viewed-categories")}}
|
||||
<MostViewedCategories @report={{report}} />
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/each}}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { service } from "@ember/service";
|
||||
import { TrackedObject } from "@ember-compat/tracked-built-ins";
|
||||
import bodyClass from "discourse/helpers/body-class";
|
||||
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 {
|
||||
@service currentUser;
|
||||
|
||||
store = new TrackedObject(
|
||||
new KeyValueStore("discourse_rewind_" + this.fetchYear)
|
||||
);
|
||||
@ -26,7 +28,7 @@ export default class AvatarDecorator extends Component {
|
||||
}
|
||||
|
||||
get showDecorator() {
|
||||
return isRewindActive() && !this.dismissed;
|
||||
return this.currentUser?.is_rewind_active && !this.dismissed;
|
||||
}
|
||||
|
||||
<template>
|
||||
|
||||
@ -4,17 +4,20 @@ import { service } from "@ember/service";
|
||||
import DButton from "discourse/components/d-button";
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
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 currentUser;
|
||||
|
||||
store = new KeyValueStore("discourse_rewind_" + this.fetchYear);
|
||||
|
||||
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() {
|
||||
const currentDate = new Date();
|
||||
const currentMonth = currentDate.getMonth();
|
||||
|
||||
@ -1,19 +1,22 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { service } from "@ember/service";
|
||||
import DNavigationItem from "discourse/components/d-navigation-item";
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
import { i18n } from "discourse-i18n";
|
||||
import isRewindActive from "discourse/plugins/discourse-rewind/discourse/lib/is-rewind-active";
|
||||
|
||||
const RewindTab = <template>
|
||||
{{#if isRewindActive}}
|
||||
<DNavigationItem
|
||||
@route="userActivity.rewind"
|
||||
@ariaCurrentContext="subNav"
|
||||
class="user-nav__activity-rewind"
|
||||
>
|
||||
{{icon "repeat"}}
|
||||
<span>{{i18n "discourse_rewind.title"}}</span>
|
||||
</DNavigationItem>
|
||||
{{/if}}
|
||||
</template>;
|
||||
export default class RewindTab extends Component {
|
||||
@service currentUser;
|
||||
|
||||
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>
|
||||
}
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
export default function isRewindActive() {
|
||||
const currentDate = new Date();
|
||||
const currentMonth = currentDate.getMonth();
|
||||
return currentMonth === 0 || currentMonth === 11;
|
||||
}
|
||||
@ -8,8 +8,8 @@
|
||||
@import "best-posts";
|
||||
@import "best-topics";
|
||||
@import "top-words";
|
||||
@import "favorite-tags";
|
||||
@import "favorite-categories";
|
||||
@import "most-viewed-tags";
|
||||
@import "most-viewed-categories";
|
||||
@import "fonts";
|
||||
@import "reading-time";
|
||||
@import "fbff";
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
.-favorite-categories {
|
||||
.-most-viewed-categories {
|
||||
.rewind-report-container {
|
||||
display: flex;
|
||||
gap: 0.5em;
|
||||
@ -16,6 +16,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.favorite-categories__category {
|
||||
.most-viewed-categories__category {
|
||||
font-family: var(--pixel-text);
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
.-favorite-tags {
|
||||
.-most-viewed-tags {
|
||||
.rewind-report-container {
|
||||
display: flex;
|
||||
gap: 0.5em;
|
||||
@ -16,6 +16,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.favorite-tags__tag {
|
||||
.most-viewed-tags__tag {
|
||||
font-family: var(--pixel-text);
|
||||
}
|
||||
@ -23,14 +23,14 @@ en:
|
||||
title: Most received reactions in topics
|
||||
fbff:
|
||||
title: Your FBFF (Forum Best Friend Forever)
|
||||
favorite_categories:
|
||||
most_viewed_categories:
|
||||
title:
|
||||
one: Your favorite category
|
||||
other: Your %{count} favorite categories
|
||||
favorite_tags:
|
||||
one: Your most viewed category
|
||||
other: Your %{count} most viewed categories
|
||||
most_viewed_tags:
|
||||
title:
|
||||
one: Your favorite tag
|
||||
other: Your %{count} favorite tags
|
||||
one: Your most viewed tag
|
||||
other: Your %{count} most viewed tags
|
||||
best_topics:
|
||||
title:
|
||||
one: Your best topic
|
||||
|
||||
@ -1 +1,3 @@
|
||||
en:
|
||||
site_settings:
|
||||
discourse_rewind_enabled: "Enable Discourse Rewind for a fun end-of-year summary for members' activity in the community."
|
||||
|
||||
12
plugin.rb
12
plugin.rb
@ -1,11 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# name: discourse-rewind
|
||||
# about: TODO
|
||||
# meta_topic_id: TODO
|
||||
# about: A fun end-of-year summary for members' activity in the community.
|
||||
# meta_topic_id: https://meta.discourse.org/t/discourse-rewind-2024/348063
|
||||
# version: 0.0.1
|
||||
# authors: Discourse
|
||||
# url: TODO
|
||||
# url: https://github.com/discourse/discourse-rewind
|
||||
# required_version: 2.7.0
|
||||
|
||||
enabled_site_setting :discourse_rewind_enabled
|
||||
@ -25,4 +25,8 @@ end
|
||||
|
||||
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
|
||||
|
||||
@ -31,7 +31,7 @@ describe "DiscourseRewind | rewind tab", type: :system do
|
||||
context "when in november" do
|
||||
before { freeze_time DateTime.parse("2022-11-24") }
|
||||
|
||||
it "doesn show the tab" do
|
||||
it "doesn't show the tab" do
|
||||
visit("/my/activity")
|
||||
|
||||
expect(page).to have_no_selector(".user-nav__activity-rewind")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user