From 2cb97d8de475b74dd9b25dfecc7c339a62383299 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Thu, 28 Jul 2022 21:12:48 +0400 Subject: [PATCH] FEATURE: show user status on the user profile page (#17712) --- .../app/components/user-status-message.js | 26 ++++ .../javascripts/discourse/app/routes/user.js | 2 + .../components/user-status-message.hbs | 21 ++++ .../discourse/app/templates/user.hbs | 8 +- .../acceptance/user-profile-summary-test.js | 115 ++++++++++++++++++ .../discourse/tests/acceptance/user-test.js | 77 ------------ .../components/user-status-message-test.js | 114 +++++++++++++++++ .../stylesheets/common/components/_index.scss | 1 + .../components/user-status-message.scss | 17 +++ 9 files changed, 303 insertions(+), 78 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/user-status-message.js create mode 100644 app/assets/javascripts/discourse/app/templates/components/user-status-message.hbs create mode 100644 app/assets/javascripts/discourse/tests/acceptance/user-profile-summary-test.js create mode 100644 app/assets/javascripts/discourse/tests/integration/components/user-status-message-test.js create mode 100644 app/assets/stylesheets/common/components/user-status-message.scss diff --git a/app/assets/javascripts/discourse/app/components/user-status-message.js b/app/assets/javascripts/discourse/app/components/user-status-message.js new file mode 100644 index 00000000000..b36791c85d0 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/user-status-message.js @@ -0,0 +1,26 @@ +import Component from "@ember/component"; +import { computed } from "@ember/object"; +import I18n from "I18n"; + +export default class extends Component { + tagName = ""; + + @computed("status.ends_at") + get until() { + if (!this.status.ends_at) { + return null; + } + + const timezone = this.currentUser.timezone; + const endsAt = moment.tz(this.status.ends_at, timezone); + const now = moment.tz(timezone); + const until = I18n.t("user_status.until"); + + if (now.isSame(endsAt, "day")) { + const localeData = moment.localeData(this.currentUser.locale); + return `${until} ${endsAt.format(localeData.longDateFormat("LT"))}`; + } else { + return `${until} ${endsAt.format("MMM D")}`; + } + } +} diff --git a/app/assets/javascripts/discourse/app/routes/user.js b/app/assets/javascripts/discourse/app/routes/user.js index e88075cfd60..c33c8d1b6cc 100644 --- a/app/assets/javascripts/discourse/app/routes/user.js +++ b/app/assets/javascripts/discourse/app/routes/user.js @@ -47,6 +47,7 @@ export default DiscourseRoute.extend({ return user .findDetails() .then(() => user.findStaffInfo()) + .then(() => user.trackStatus()) .catch(() => this.replaceWith("/404")); }, @@ -87,6 +88,7 @@ export default DiscourseRoute.extend({ const user = this.modelFor("user"); this.messageBus.unsubscribe(`/u/${user.username_lower}`); this.messageBus.unsubscribe(`/u/${user.username_lower}/counters`); + user.stopTrackingStatus(); // Remove the search context this.searchService.set("searchContext", null); diff --git a/app/assets/javascripts/discourse/app/templates/components/user-status-message.hbs b/app/assets/javascripts/discourse/app/templates/components/user-status-message.hbs new file mode 100644 index 00000000000..a6bb89864f3 --- /dev/null +++ b/app/assets/javascripts/discourse/app/templates/components/user-status-message.hbs @@ -0,0 +1,21 @@ + + {{emoji @status.emoji skipTitle=true}} + {{#if @showDescription}} + + {{@status.description}} + + {{/if}} + +
+ {{emoji @status.emoji skipTitle=true}} + + {{@status.description}} + + {{#if this.until}} +
+ {{this.until}} +
+ {{/if}} +
+
+
diff --git a/app/assets/javascripts/discourse/app/templates/user.hbs b/app/assets/javascripts/discourse/app/templates/user.hbs index c728f78cb46..c990875aaf6 100644 --- a/app/assets/javascripts/discourse/app/templates/user.hbs +++ b/app/assets/javascripts/discourse/app/templates/user.hbs @@ -79,7 +79,13 @@