Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -12,12 +12,12 @@ class FavoriteCategories < BaseReport
{ 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")
Expand All @@ -30,7 +30,7 @@ def call
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -12,13 +12,13 @@ class FavoriteTags < BaseReport
{ 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")
Expand All @@ -32,7 +32,7 @@ def call
.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
Expand Down
12 changes: 9 additions & 3 deletions app/services/discourse_rewind/fetch_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class FetchReports
Action::ReadingTime,
Action::Reactions,
Action::Fbff,
Action::FavoriteTags,
Action::FavoriteCategories,
Action::MostViewedTags,
Action::MostViewedCategories,
Action::BestTopics,
Action::BestPosts,
Action::ActivityCalendar,
Expand Down Expand Up @@ -62,7 +62,13 @@ def fetch_year
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

Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -22,4 +22,4 @@ const FavoriteCategories = <template>
{{/if}}
</template>;

export default FavoriteCategories;
export default MostViewedCategories;
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -22,4 +22,4 @@ const FavoriteTags = <template>
{{/if}}
</template>;

export default FavoriteTags;
export default MostViewedTags;
12 changes: 6 additions & 6 deletions assets/javascripts/discourse/components/rewind.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
);
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
}
5 changes: 0 additions & 5 deletions assets/javascripts/discourse/lib/is-rewind-active.js

This file was deleted.

4 changes: 2 additions & 2 deletions assets/stylesheets/common/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.-favorite-categories {
.-most-viewed-categories {
.rewind-report-container {
display: flex;
gap: 0.5em;
Expand All @@ -16,6 +16,6 @@
}
}

.favorite-categories__category {
.most-viewed-categories__category {
font-family: var(--pixel-text);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.-favorite-tags {
.-most-viewed-tags {
.rewind-report-container {
display: flex;
gap: 0.5em;
Expand All @@ -16,6 +16,6 @@
}
}

.favorite-tags__tag {
.most-viewed-tags__tag {
font-family: var(--pixel-text);
}
12 changes: 6 additions & 6 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 4 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,4 +25,8 @@ def self.public_asset_path(name)

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
2 changes: 1 addition & 1 deletion spec/system/rewind_tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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")
Expand Down