Skip to content

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

UX: moves rewind link inside profile tab (#36564)

Joffrey JAFFEUXdc16beb7102c
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 aa2a434d992..68d64511515 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
@@ -125,7 +125,7 @@ export default class WritingAnalysis extends Component {
<div class="writing-analysis__release-meta">
{{i18n
"discourse_rewind.reports.writing_analysis.release_info"
- rewindYear=(this.rewind.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
deleted file mode 100644
index fc7f454c47b..00000000000
--- a/plugins/discourse-rewind/assets/javascripts/discourse/components/rewind-header-icon.gjs
+++ /dev/null
@@ -1,100 +0,0 @@
-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/initializers/rewind-setup.js b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
index ebb967b9eab..27d3dadf8a2 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
@@ -1,11 +1,13 @@
import { withPluginApi } from "discourse/lib/plugin-api";
-import RewindHeaderIcon from "../components/rewind-header-icon";
+import { i18n } from "discourse-i18n";
export default {
name: "discourse-rewind-setup",
+
initialize(container) {
this.siteSettings = container.lookup("service:site-settings");
this.currentUser = container.lookup("service:current-user");
+ this.rewind = container.lookup("service:rewind");
if (!this.currentUser) {
return;
@@ -16,8 +18,12 @@ export default {
}
withPluginApi((api) => {
- api.headerIcons.add("discourse-rewind", RewindHeaderIcon, {
- before: "hamburger",
+ api.addQuickAccessProfileItem({
+ icon: "repeat",
+ href: "/my/activity/rewind",
+ content: i18n("discourse_rewind.profile_link", {
+ rewindYear: this.rewind.fetchRewindYear,
+ }),
});
});
},
diff --git a/plugins/discourse-rewind/assets/stylesheets/common/_index.scss b/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
index 4024a857135..162a33565dc 100644
--- a/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
+++ b/plugins/discourse-rewind/assets/stylesheets/common/_index.scss
@@ -15,7 +15,6 @@
@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
deleted file mode 100644
index 13bdc02d148..00000000000
--- a/plugins/discourse-rewind/assets/stylesheets/common/rewind-header-icon.scss
+++ /dev/null
@@ -1,28 +0,0 @@
-.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 f136cfd182c..da930c3a176 100644
--- a/plugins/discourse-rewind/config/locales/client.en.yml
+++ b/plugins/discourse-rewind/config/locales/client.en.yml
@@ -11,11 +11,7 @@ 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"
+ profile_link: "View your %{rewindYear} Discourse Rewind"
reports:
activity_calendar:
title: Activity Calendar
diff --git a/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
index 34b0857e4e7..02a801e19f5 100644
--- a/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
+++ b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
@@ -72,6 +72,14 @@ module PageObjects
def on_rewind_page?(username)
has_current_path?("/u/#{username}/activity/rewind")
end
+
+ def has_rewind_profile_link?
+ has_css?("#quick-access-profile a[href*='/activity/rewind']")
+ end
+
+ def has_no_rewind_profile_link?
+ has_no_css?("#quick-access-profile a[href*='/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
deleted file mode 100644
index 5bc3e375855..00000000000
--- a/plugins/discourse-rewind/spec/system/rewind_callout_spec.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-# frozen_string_literal: true
-
-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(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_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
-
- 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(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
-
- context "when in november" do
- before { freeze_time DateTime.parse("2022-11-24") }
-
- it "doesn't show the avatar decoration and callout" do
- visit("/")
-
- 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_profile_tab_spec.rb b/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb
new file mode 100644
index 00000000000..432725ca975
--- /dev/null
+++ b/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+describe "DiscourseRewind | rewind profile link", type: :system do
+ fab!(:current_user, :user)
+
+ let(:rewind_page) { PageObjects::Pages::Rewind.new }
+ let(:user_menu) { PageObjects::Components::UserMenu.new }
+
+ before do
+ sign_in(current_user)
+ freeze_time(DateTime.parse("2022-12-05"))
+ end
+
+ it "does not show the profile link when the plugin is disabled" do
+ SiteSetting.discourse_rewind_enabled = false
+
+ visit("/")
+ user_menu.open
+ user_menu.click_profile_tab
+
+ expect(rewind_page).to have_no_rewind_profile_link
+ end
+
+ it "shows the profile link when the plugin is enabled" do
+ SiteSetting.discourse_rewind_enabled = true
+
+ visit("/")
+ user_menu.open
+ user_menu.click_profile_tab
+
+ expect(rewind_page).to have_rewind_profile_link
+ end
+end