Skip to content

A platform for community discussion. Free, open, simple.

UX: Rewind feedback and fixes 1 (#36555)

Martin Brennan3bb6ceeea95f
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/base_report.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/base_report.rb
index fab2c8c2a0d..c796811d33e 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/base_report.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/base_report.rb
@@ -15,6 +15,7 @@ module DiscourseRewind
end
def should_use_fake_data?
+ return false if ENV["DISCOURSE_REWIND_USE_REAL_DATA"] == "1"
Rails.env.development?
end
end
diff --git a/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb b/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
index b27b4a64297..3a699ea1069 100644
--- a/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
+++ b/plugins/discourse-rewind/app/services/discourse_rewind/action/chat_usage.rb
@@ -9,11 +9,11 @@ module DiscourseRewind
data: {
total_messages: 342,
favorite_channels: [
- { channel_id: 1, channel_name: "general", message_count: 156 },
- { channel_id: 2, channel_name: "tech-talk", message_count: 89 },
- { channel_id: 3, channel_name: "random", message_count: 45 },
- { channel_id: 4, channel_name: "dev", message_count: 32 },
- { channel_id: 5, channel_name: "announcements", message_count: 12 },
+ { channel_id: 1, channel_slug: "general", message_count: 156 },
+ { channel_id: 2, channel_slug: "tech-talk", message_count: 89 },
+ { channel_id: 3, channel_slug: "random", message_count: 45 },
+ { channel_id: 4, channel_slug: "dev", message_count: 32 },
+ { channel_id: 5, channel_slug: "announcements", message_count: 12 },
],
dm_message_count: 87,
unique_dm_channels: 12,
@@ -39,12 +39,12 @@ module DiscourseRewind
messages
.joins(:chat_channel)
.where(chat_channels: { type: "CategoryChannel" })
- .group("chat_channels.id", "chat_channels.name")
+ .group("chat_channels.id", "chat_channels.slug")
.count
.sort_by { |_, count| -count }
.first(5)
- .map do |(id, name), count|
- { channel_id: id, channel_name: name, message_count: count }
+ .map do |(id, slug), count|
+ { channel_id: id, channel_slug: slug, message_count: count }
end
# DM statistics
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/chat-usage.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/chat-usage.gjs
index f1a4ccca04c..ef0b2d182d5 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/chat-usage.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/chat-usage.gjs
@@ -141,7 +141,7 @@ export default class ChatUsage extends Component {
>
<span
class="chat-channel-link__name"
- >#{{channel.channel_name}}</span>
+ >#{{channel.channel_slug}}</span>
<span class="chat-channel-link__count">
{{number channel.message_count}}
</span>
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/header.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/header.gjs
index cd0d8c1c88a..68857e445d0 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/header.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/header.gjs
@@ -1,43 +1,46 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import { i18n } from "discourse-i18n";
-import { fetchRewindYear } from "../../connectors/before-panel-body/rewind-callout";
-const RewindHeader = <template>
- <div class="rewind__header">
- <div class="rewind__header-logo">
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1 104 106">
- <path
- fill="#231f20"
- d="M51.87 0C23.71 0 0 22.83 0 51v52.81l51.86-.05c28.16 0 51-23.71 51-51.87S80 0 51.87 0Z"
- />
- <path
- fill="#fff9ae"
- d="M52.37 19.74a31.62 31.62 0 0 0-27.79 46.67l-5.72 18.4 20.54-4.64a31.61 31.61 0 1 0 13-60.43Z"
- />
- <path
- fill="#00aeef"
- d="M77.45 32.12a31.6 31.6 0 0 1-38.05 48l-20.54 4.7 20.91-2.47a31.6 31.6 0 0 0 37.68-50.23Z"
- />
- <path
- fill="#00a94f"
- d="M71.63 26.29A31.6 31.6 0 0 1 38.8 78l-19.94 6.82 20.54-4.65a31.6 31.6 0 0 0 32.23-53.88Z"
- />
- <path
- fill="#f15d22"
- d="M26.47 67.11a31.61 31.61 0 0 1 51-35 31.61 31.61 0 0 0-52.89 34.3l-5.72 18.4Z"
- />
- <path
- fill="#e31b23"
- d="M24.58 66.41a31.61 31.61 0 0 1 47.05-40.12 31.61 31.61 0 0 0-49 39.63l-3.76 18.9Z"
- />
- </svg>
- <div class="rewind__header-title">
- {{i18n "discourse_rewind.title"}}
- </div>
- <div class="rewind__header-year">
- {{fetchRewindYear}}
+export default class RewindHeader extends Component {
+ @service rewind;
+
+ <template>
+ <div class="rewind__header">
+ <div class="rewind__header-logo">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1 104 106">
+ <path
+ fill="#231f20"
+ d="M51.87 0C23.71 0 0 22.83 0 51v52.81l51.86-.05c28.16 0 51-23.71 51-51.87S80 0 51.87 0Z"
+ />
+ <path
+ fill="#fff9ae"
+ d="M52.37 19.74a31.62 31.62 0 0 0-27.79 46.67l-5.72 18.4 20.54-4.64a31.61 31.61 0 1 0 13-60.43Z"
+ />
+ <path
+ fill="#00aeef"
+ d="M77.45 32.12a31.6 31.6 0 0 1-38.05 48l-20.54 4.7 20.91-2.47a31.6 31.6 0 0 0 37.68-50.23Z"
+ />
+ <path
+ fill="#00a94f"
+ d="M71.63 26.29A31.6 31.6 0 0 1 38.8 78l-19.94 6.82 20.54-4.65a31.6 31.6 0 0 0 32.23-53.88Z"
+ />
+ <path
+ fill="#f15d22"
+ d="M26.47 67.11a31.61 31.61 0 0 1 51-35 31.61 31.61 0 0 0-52.89 34.3l-5.72 18.4Z"
+ />
+ <path
+ fill="#e31b23"
+ d="M24.58 66.41a31.61 31.61 0 0 1 47.05-40.12 31.61 31.61 0 0 0-49 39.63l-3.76 18.9Z"
+ />
+ </svg>
+ <div class="rewind__header-title">
+ {{i18n "discourse_rewind.title"}}
+ </div>
+ <div class="rewind__header-year">
+ {{this.rewind.fetchRewindYear}}
+ </div>
</div>
</div>
- </div>
-</template>;
-
-export default RewindHeader;
+ </template>
+}
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/writing-analysis.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/writing-analysis.gjs
index b06c9975db9..aa2a434d992 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/writing-analysis.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/components/reports/writing-analysis.gjs
@@ -3,11 +3,13 @@ import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
+import { service } from "@ember/service";
import number from "discourse/helpers/number";
import { i18n } from "discourse-i18n";
-import { fetchRewindYear } from "../../connectors/before-panel-body/rewind-callout";
export default class WritingAnalysis extends Component {
+ @service rewind;
+
@tracked currentColorIndex = 0;
terminalColors = ["#0f0", "#ffbf00", "#00ffff", "#ff00ff"];
@@ -123,7 +125,7 @@ export default class WritingAnalysis extends Component {
<div class="writing-analysis__release-meta">
{{i18n
"discourse_rewind.reports.writing_analysis.release_info"
- rewindYear=(fetchRewindYear)
+ rewindYear=(this.rewind.fetchRewindYear)
}}
<span>&lt;3</span>
</div>
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/components/rewind-header-icon.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/components/rewind-header-icon.gjs
new file mode 100644
index 00000000000..fc7f454c47b
--- /dev/null
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/components/rewind-header-icon.gjs
@@ -0,0 +1,100 @@
+import Component from "@glimmer/component";
+import { array, hash } from "@ember/helper";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import { htmlSafe } from "@ember/template";
+import DButton from "discourse/components/d-button";
+import DTooltip from "discourse/float-kit/components/d-tooltip";
+import concatClass from "discourse/helpers/concat-class";
+import icon from "discourse/helpers/d-icon";
+import getURL from "discourse/lib/get-url";
+import { i18n } from "discourse-i18n";
+import RewindHeader from "discourse/plugins/discourse-rewind/discourse/components/reports/header";
+
+export default class RewindHeaderIcon extends Component {
+ @service rewind;
+ @service router;
+
+ constructor() {
+ super(...arguments);
+ this.router.on("routeWillChange", this.closeTooltip);
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.router.off("routeWillChange", this.closeTooltip);
+ }
+
+ get href() {
+ return getURL("/my/activity/rewind");
+ }
+
+ get title() {
+ return i18n("discourse_rewind.header_tooltip.title", {
+ rewindYear: this.rewind.fetchRewindYear,
+ });
+ }
+
+ get shouldDisplay() {
+ return this.rewind.dismissed && !this.rewind.disabled;
+ }
+
+ get preferencesUrl() {
+ return getURL("/my/preferences/rewind");
+ }
+
+ @action
+ registerTooltip(tooltipInstance) {
+ this.tooltipInstance = tooltipInstance;
+ }
+
+ @action
+ closeTooltip() {
+ this.tooltipInstance?.close();
+ }
+
+ <template>
+ {{#if this.shouldDisplay}}
+ <li class="header-dropdown-toggle rewind-header-icon">
+ <DTooltip
+ @identifier="rewind-header-icon-tooltip"
+ @triggers={{hash mobile=(array "click") desktop=(array "click")}}
+ @onRegisterApi={{this.registerTooltip}}
+ >
+ <:trigger>
+ <DButton
+ tabindex="0"
+ class={{concatClass "icon" "btn-flat"}}
+ title={{this.title}}
+ >
+ {{~icon "backward-fast"~}}
+ </DButton>
+ </:trigger>
+ <:content>
+ <RewindHeader />
+
+ <p>{{i18n
+ "discourse_rewind.header_tooltip.description"
+ rewindYear=this.rewind.fetchRewindYear
+ nextYear=this.rewind.fetchRewindNextYear
+ }}</p>
+ <DButton
+ @href={{this.href}}
+ class="rewind-header-icon__button btn-primary"
+ >
+ {{i18n "discourse_rewind.header_tooltip.take_me_there"}}
+ </DButton>
+
+ <p class="rewind-header-icon__preferences">
+ {{htmlSafe
+ (i18n
+ "discourse_rewind.header_tooltip.preferences_link"
+ preferencesUrl=this.preferencesUrl
+ )
+ }}</p>
+ </:content>
+ </DTooltip>
+ </li>
+ {{/if}}
+ </template>
+}
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/after-header-panel/rewind-decoration.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/after-header-panel/rewind-decoration.gjs
index ab4c585b825..ef6c82ae1e4 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/after-header-panel/rewind-decoration.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/after-header-panel/rewind-decoration.gjs
@@ -1,23 +1,17 @@
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 { fetchRewindYear } from "../before-panel-body/rewind-callout";
export default class AvatarDecorator extends Component {
@service currentUser;
-
- store = new TrackedObject(
- new KeyValueStore("discourse_rewind_" + fetchRewindYear())
- );
-
- get dismissed() {
- return this.store.getObject("_dismissed") ?? false;
- }
+ @service rewind;
get showDecorator() {
- return this.currentUser?.is_rewind_active && !this.dismissed;
+ return (
+ this.currentUser?.is_rewind_active &&
+ !this.rewind.dismissed &&
+ !this.rewind.disabled
+ );
}
<template>
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/before-panel-body/rewind-callout.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/before-panel-body/rewind-callout.gjs
index a2e000d0be6..493d1f170d6 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/before-panel-body/rewind-callout.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/before-panel-body/rewind-callout.gjs
@@ -3,41 +3,24 @@ import { action } from "@ember/object";
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 { i18n } from "discourse-i18n";
-// 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).
-export function fetchRewindYear() {
- const currentDate = new Date();
- const currentMonth = currentDate.getMonth();
- const currentYear = currentDate.getFullYear();
-
- if (currentMonth === 0) {
- return currentYear - 1;
- } else {
- return currentYear;
- }
-}
-
export default class RewindCallout extends Component {
@service router;
@service currentUser;
-
- store = new KeyValueStore("discourse_rewind_" + fetchRewindYear());
+ @service rewind;
get showCallout() {
- return this.currentUser?.is_rewind_active && !this.dismissed;
- }
-
- get dismissed() {
- return this.store.getObject("_dismissed") ?? false;
+ return (
+ this.currentUser?.is_rewind_active &&
+ !this.rewind.dismissed &&
+ !this.rewind.disabled
+ );
}
@action
openRewind() {
- this.store.setObject({ key: "_dismissed", value: true });
+ this.rewind.dismiss();
this.router.transitionTo("/my/activity/rewind");
}
@@ -105,7 +88,7 @@ export default class RewindCallout extends Component {
text-anchor="middle"
dominant-baseline="middle"
style="font-size: 32px; font-weight: bold; fill: #010101;"
- >{{fetchRewindYear}}</text>
+ >{{this.rewind.fetchRewindYear}}</text>
</svg>
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-activity-bottom/rewind-tab.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-activity-bottom/rewind-tab.gjs
index c94668d3711..ac259a7f5f9 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-activity-bottom/rewind-tab.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-activity-bottom/rewind-tab.gjs
@@ -6,9 +6,14 @@ import { i18n } from "discourse-i18n";
export default class RewindTab extends Component {
@service currentUser;
+ @service rewind;
+
+ get showNavTab() {
+ return this.currentUser?.is_rewind_active && !this.rewind.disabled;
+ }
<template>
- {{#if this.currentUser.is_rewind_active}}
+ {{#if this.showNavTab}}
<DNavigationItem
@route="userActivity.rewind"
@ariaCurrentContext="subNav"
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/controllers/preferences/rewind.js b/plugins/discourse-rewind/assets/javascripts/discourse/controllers/preferences/rewind.js
index 05a393f0187..431bd954702 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/controllers/preferences/rewind.js
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/controllers/preferences/rewind.js
@@ -1,11 +1,14 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
+import { service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { i18n } from "discourse-i18n";
const REWIND_ATTRS = ["discourse_rewind_disabled"];
export default class PreferencesRewindController extends Controller {
+ @service rewind;
+
subpageTitle = i18n("discourse_rewind.title");
@action
@@ -15,6 +18,7 @@ export default class PreferencesRewindController extends Controller {
.save(REWIND_ATTRS)
.then(() => {
this.set("saved", true);
+ this.rewind.disabled = this.model.user_option.discourse_rewind_disabled;
})
.catch(popupAjaxError);
}
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
new file mode 100644
index 00000000000..ebb967b9eab
--- /dev/null
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
@@ -0,0 +1,24 @@
+import { withPluginApi } from "discourse/lib/plugin-api";
+import RewindHeaderIcon from "../components/rewind-header-icon";
+
+export default {
+ name: "discourse-rewind-setup",
+ initialize(container) {
+ this.siteSettings = container.lookup("service:site-settings");
+ this.currentUser = container.lookup("service:current-user");
+
+ if (!this.currentUser) {
+ return;
+ }
+
+ if (!this.currentUser.is_rewind_active) {
+ return;
+ }
+
+ withPluginApi((api) => {
+ api.headerIcons.add("discourse-rewind", RewindHeaderIcon, {
+ before: "hamburger",
+ });
+ });
+ },
+};
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/services/rewind.js b/plugins/discourse-rewind/assets/javascripts/discourse/services/rewind.js
new file mode 100644
index 00000000000..05658a9908c
--- /dev/null
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/services/rewind.js
@@ -0,0 +1,54 @@
+import { tracked } from "@glimmer/tracking";
+import Service, { service } from "@ember/service";
+import KeyValueStore from "discourse/lib/key-value-store";
+
+export default class Rewind extends Service {
+ @service currentUser;
+
+ @tracked dismissed = this.store.getObject("_dismissed") ?? false;
+
+ store = new KeyValueStore("discourse_rewind_" + this.fetchRewindYear);
+
+ @tracked
+ _isDisabled = this.currentUser?.user_option?.discourse_rewind_disabled;
+
+ get disabled() {
+ return this._isDisabled ?? false;
+ }
+
+ set disabled(value) {
+ this._isDisabled = value;
+ }
+
+ // 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 fetchRewindYear() {
+ const currentDate = new Date();
+ const currentMonth = currentDate.getMonth();
+ const currentYear = currentDate.getFullYear();
+
+ if (currentMonth === 0) {
+ return currentYear - 1;
+ } else {
+ return currentYear;
+ }
+ }
+
+ get fetchRewindNextYear() {
+ const currentDate = new Date();
+ const currentMonth = currentDate.getMonth();
+ const currentYear = currentDate.getFullYear();
+
+ if (currentMonth === 0) {
+ return currentYear;
+ } else {
+ return currentYear + 1;
+ }
+ }
+
+ dismiss() {
+ this.dismissed = true;
+ this.store.setObject({ key: "_dismissed", value: true });
+ }
+}
diff --git a/plugins/discourse-rewind/assets/stylesheets/common/_index.scss b/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
index 162a33565dc..4024a857135 100644
--- a/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
+++ b/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
@@ -15,6 +15,7 @@
@import "fbff";
@import "writing-analysis";
@import "rewind-header";
+@import "rewind-header-icon";
@import "rewind-callout";
@import "folder-styles";
@import "time-of-day-activity";
diff --git a/plugins/discourse-rewind/assets/stylesheets/common/rewind-header-icon.scss b/plugins/discourse-rewind/assets/stylesheets/common/rewind-header-icon.scss
new file mode 100644
index 00000000000..13bdc02d148
--- /dev/null
+++ b/plugins/discourse-rewind/assets/stylesheets/common/rewind-header-icon.scss
@@ -0,0 +1,28 @@
+.rewind-header-icon-tooltip-content {
+ .fk-d-tooltip__inner-content {
+ flex-direction: column;
+ justify-content: center;
+ text-align: center;
+ padding: 0;
+ z-index: z("max");
+
+ .rewind__header {
+ width: 100%;
+ }
+ }
+
+ .d-icon-tippy-rounded-arrow {
+ z-index: z("modal", "dialog");
+ }
+}
+
+.rewind-header-icon {
+ &__button {
+ margin-bottom: 0.5em;
+ }
+
+ &__preferences {
+ font-size: var(--font-down-3);
+ padding: 0 1em;
+ }
+}
diff --git a/plugins/discourse-rewind/config/locales/client.en.yml b/plugins/discourse-rewind/config/locales/client.en.yml
index 7ee7458af7b..f136cfd182c 100644
--- a/plugins/discourse-rewind/config/locales/client.en.yml
+++ b/plugins/discourse-rewind/config/locales/client.en.yml
@@ -11,6 +11,11 @@ en:
loading: "Reticulating splines..."
preferences:
disable_rewind: "Disable Discourse Rewind. This hides the year-end activity summary in your profile and on your avatar."
+ header_tooltip:
+ title: "View your %{rewindYear} Discourse Rewind"
+ description: "You can view your %{rewindYear} Discourse Rewind until February %{nextYear}"
+ take_me_there: "Take me there!"
+ preferences_link: "P.S. You can <a href='%{preferencesUrl}'>turn off Discourse Rewind in your preferences</a> at any time"
reports:
activity_calendar:
title: Activity Calendar
@@ -83,7 +88,7 @@ en:
status_online: "● online"
message_1: "You sent <strong>%{count}</strong> messages this year!"
reply_1: "lol awesome B-)"
- message_2: "You had <strong>%{dm_count}</strong> DM conversations with <strong>%{channel_count}</strong> different people"
+ message_2: "You had <strong>%{dm_count}</strong> DM conversations with <strong>%{channel_count}</strong> different people or groups"
reply_2: "cOo0oL :D"
message_3: "People loved your messages! You got <strong>%{count}</strong> reactions ❤️"
reply_3: "r0fl rAwr 8-)"
diff --git a/plugins/discourse-rewind/plugin.rb b/plugins/discourse-rewind/plugin.rb
index f7a5e7ce659..68724e9fc16 100644
--- a/plugins/discourse-rewind/plugin.rb
+++ b/plugins/discourse-rewind/plugin.rb
@@ -27,6 +27,34 @@ module ::DiscourseRewind
def self.public_asset_path(name)
File.expand_path(File.join(__dir__, "public", name))
end
+
+ def self.year_date_range(date_override = nil)
+ if date_override.present?
+ current_date = date_override
+ else
+ current_date = Time.zone.now
+ end
+
+ current_month = current_date.month
+ current_year = current_date.year
+
+ case current_month
+ when 1
+ current_year - 1
+ when 12
+ current_year
+ else
+ # Otherwise it's impossible to test in browser locally unless you're
+ # in December or January
+ if Rails.env.development?
+ current_year
+ else
+ false
+ end
+ end
+
+ Date.new(current_year).all_year
+ end
end
require_relative "lib/discourse_rewind/engine"
@@ -41,7 +69,6 @@ after_initialize do
end
add_to_serializer(:current_user, :is_rewind_active) do
- return false if object.user_option&.discourse_rewind_disabled
Rails.env.development? || Date.today.month == 1 || Date.today.month == 12
end
diff --git a/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
new file mode 100644
index 00000000000..34b0857e4e7
--- /dev/null
+++ b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class Rewind < PageObjects::Pages::Base
+ def visit_activity(username)
+ page.visit("/u/#{username}/activity")
+ self
+ end
+
+ def visit_my_activity
+ page.visit("/my/activity")
+ self
+ end
+
+ def has_rewind_tab?
+ has_selector?(".user-nav__activity-rewind")
+ end
+
+ def has_no_rewind_tab?
+ has_no_selector?(".user-nav__activity-rewind")
+ end
+
+ def has_rewind_notification_active?
+ has_css?("body.rewind-notification-active")
+ end
+
+ def has_no_rewind_notification_active?
+ has_no_css?("body.rewind-notification-active")
+ end
+
+ def has_rewind_header_icon?
+ has_css?(".rewind-header-icon")
+ end
+
+ def has_no_rewind_header_icon?
+ has_no_css?(".rewind-header-icon")
+ end
+
+ def click_rewind_header_icon
+ find(".rewind-header-icon").click
+ end
+
+ def click_header_tooltip_cta
+ find(".rewind-header-icon-tooltip-content .rewind-header-icon__button").click
+ end
+
+ def click_header_tooltip_preferences_link
+ find(".rewind-header-icon-tooltip-content .rewind-header-icon__preferences a").click
+ end
+
+ def open_user_menu
+ find("#toggle-current-user").click
+ end
+
+ def has_callout?
+ has_css?(".rewind-callout__container")
+ end
+
+ def has_no_callout?
+ has_no_css?(".rewind-callout__container")
+ end
+
+ def click_callout
+ find(".rewind-callout__container .rewind-callout").click
+ end
+
+ def has_rewind_header?
+ has_css?(".rewind .rewind__header")
+ end
+
+ def on_rewind_page?(username)
+ has_current_path?("/u/#{username}/activity/rewind")
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rewind/spec/system/rewind_callout_spec.rb b/plugins/discourse-rewind/spec/system/rewind_callout_spec.rb
index 7c9c7331477..5bc3e375855 100644
--- a/plugins/discourse-rewind/spec/system/rewind_callout_spec.rb
+++ b/plugins/discourse-rewind/spec/system/rewind_callout_spec.rb
@@ -2,35 +2,101 @@
describe "DiscourseRewind | rewind avatar decoration and callout", type: :system do
fab!(:current_user, :user)
+ let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
SiteSetting.discourse_rewind_enabled = true
sign_in(current_user)
end
+ def visit_and_dismiss_rewind
+ visit("/")
+
+ expect(rewind_page).to have_rewind_notification_active
+ rewind_page.open_user_menu
+ rewind_page.click_callout
+ expect(rewind_page).to have_rewind_header
+ expect(rewind_page).to be_on_rewind_page(current_user.username)
+
+ visit("/")
+ end
+
context "when in december" do
before { freeze_time DateTime.parse("2022-12-05") }
it "shows avatar decoration and callout" do
visit("/")
- expect(page).to have_css("body.rewind-notification-active")
- find("#toggle-current-user").click
- expect(page).to have_css(".rewind-callout__container")
+ expect(rewind_page).to have_rewind_notification_active
+ rewind_page.open_user_menu
+ expect(rewind_page).to have_callout
+ end
+
+ describe "header icon" do
+ # TODO (martin) Fix this spec, for some reason it makes have_rewind_header fail
+ xit "shows the correct message", time: Time.utc(2022, 12, 05) do
+ visit_and_dismiss_rewind
+
+ rewind_page.click_rewind_header_icon
+
+ expect(page).to have_content(
+ I18n.t(
+ "js.discourse_rewind.header_tooltip.description",
+ rewindYear: DiscourseRewind.year_date_range.first.year,
+ nextYear: DiscourseRewind.year_date_range.first.year + 1,
+ ),
+ )
+ end
+
+ it "can navigate to the rewind page from the tooltip" do
+ visit_and_dismiss_rewind
+
+ rewind_page.click_rewind_header_icon
+ rewind_page.click_header_tooltip_cta
+
+ expect(rewind_page).to be_on_rewind_page(current_user.username)
+ end
+
+ it "can navigate to the user rewind preferences from the tooltip" do
+ visit_and_dismiss_rewind
+
+ rewind_page.click_rewind_header_icon
+ rewind_page.click_header_tooltip_preferences_link
+
+ expect(page).to have_current_path("/u/#{current_user.username}/preferences/rewind")
+ expect(page).to have_content(I18n.t("js.discourse_rewind.preferences.disable_rewind"))
+ end
end
context "when the user dismisses rewind by clicking the callout" do
it "no longer shows the callout" do
- visit("/")
+ visit_and_dismiss_rewind
+ expect(rewind_page).to have_no_rewind_notification_active
+ end
+
+ it "shows the header icon" do
+ visit_and_dismiss_rewind
+ expect(rewind_page).to have_rewind_header_icon
+ end
+ end
- expect(page).to have_css("body.rewind-notification-active")
- find("#toggle-current-user").click
- find(".rewind-callout__container .rewind-callout").click
- expect(page).to have_css(".rewind .rewind__header")
- expect(page).to have_current_path("/u/#{current_user.username}/activity/rewind")
+ context "when user has disabled rewind" do
+ before { current_user.user_option.update!(discourse_rewind_disabled: true) }
+ it "does not show the callout" do
visit("/")
- expect(page).to have_no_css("body.rewind-notification-active")
+
+ expect(rewind_page).to have_no_rewind_notification_active
+ end
+
+ context "when user has dismissed rewind previously" do
+ it "does not show the header icon" do
+ page.execute_script "window.localStorage.setItem('discourse_d-editor-prefers-rich-editor', 'true');"
+
+ visit("/")
+
+ expect(rewind_page).to have_no_rewind_header_icon
+ end
end
end
end
@@ -41,7 +107,13 @@ describe "DiscourseRewind | rewind avatar decoration and callout", type: :system
it "doesn't show the avatar decoration and callout" do
visit("/")
- expect(page).to have_no_css("body.rewind-notification-active")
+ expect(rewind_page).to have_no_rewind_notification_active
+ end
+
+ it "doesn't show the header icon" do
+ visit("/")
+
+ expect(rewind_page).to have_no_rewind_header_icon
end
end
end
diff --git a/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb b/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
index 21c572a242c..96fbfeb126b 100644
--- a/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
+++ b/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
@@ -2,6 +2,7 @@
describe "DiscourseRewind | rewind tab", type: :system do
fab!(:current_user, :user)
+ let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
SiteSetting.discourse_rewind_enabled = true
@@ -12,9 +13,8 @@ describe "DiscourseRewind | rewind tab", type: :system do
before { freeze_time DateTime.parse("2022-01-10") }
it "shows the tab" do
- visit("/my/activity")
-
- expect(page).to have_selector(".user-nav__activity-rewind")
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_rewind_tab
end
end
@@ -22,9 +22,8 @@ describe "DiscourseRewind | rewind tab", type: :system do
before { freeze_time DateTime.parse("2022-12-05") }
it "shows the tab" do
- visit("/my/activity")
-
- expect(page).to have_selector(".user-nav__activity-rewind")
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_rewind_tab
end
end
@@ -32,9 +31,8 @@ describe "DiscourseRewind | rewind tab", type: :system do
before { freeze_time DateTime.parse("2022-11-24") }
it "doesn't show the tab" do
- visit("/my/activity")
-
- expect(page).to have_no_selector(".user-nav__activity-rewind")
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_no_rewind_tab
end
end
end
diff --git a/plugins/discourse-rewind/spec/system/user_preferences_spec.rb b/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
index 7dcbe6402d8..c4ce5451a3b 100644
--- a/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
+++ b/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
@@ -2,6 +2,7 @@
describe "DiscourseRewind | user preferences", type: :system do
fab!(:current_user, :user)
+ let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
SiteSetting.discourse_rewind_enabled = true
@@ -13,9 +14,8 @@ describe "DiscourseRewind | user preferences", type: :system do
context "when discourse_rewind_disabled is false" do
it "shows the rewind tab" do
- visit("/my/activity")
-
- expect(page).to have_selector(".user-nav__activity-rewind")
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_rewind_tab
end
end
@@ -23,9 +23,8 @@ describe "DiscourseRewind | user preferences", type: :system do
before { current_user.user_option.update!(discourse_rewind_disabled: true) }
it "does not show the rewind tab" do
- visit("/my/activity")
-
- expect(page).to have_no_selector(".user-nav__activity-rewind")
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_no_rewind_tab
end
end
end