From ec2123809fa488a748c5383bcb9936c9ce4367f2 Mon Sep 17 00:00:00 2001 From: Joe <33972521+hnb-ku@users.noreply.github.com> Date: Mon, 25 Mar 2019 20:37:17 +0800 Subject: [PATCH] FEATURE: user and group cards on mobile (#7246) --- .../components/group-card-contents.js.es6 | 8 +- .../components/user-card-contents.js.es6 | 4 +- .../discourse/controllers/user-card.js.es6 | 12 +- .../javascripts/discourse/lib/url.js.es6 | 4 + .../mixins/card-contents-base.js.es6 | 110 ++++++++------- .../components/group-card-contents.hbs | 22 +-- .../components/user-card-contents.hbs | 20 +-- .../mobile/list/topic-list-item.raw.hbs | 75 +++++----- .../discourse/templates/user-card.hbs | 5 + .../components}/user-card.scss | 132 ++++++++---------- app/assets/stylesheets/desktop.scss | 1 - .../desktop/components/user-card.scss | 52 +++++++ .../mobile/components/user-card.scss | 88 ++++++++++++ app/assets/stylesheets/mobile/discourse.scss | 14 ++ script/benchmarks/markdown/giant_post.md | 1 - .../acceptance/group-card-mobile-test.js.es6 | 15 +- .../acceptance/group-card-test.js.es6 | 8 ++ .../acceptance/user-card-mobile-test.js.es6 | 22 +++ .../acceptance/user-card-test.js.es6 | 9 +- 19 files changed, 410 insertions(+), 192 deletions(-) rename app/assets/stylesheets/{desktop => common/components}/user-card.scss (77%) create mode 100644 app/assets/stylesheets/desktop/components/user-card.scss create mode 100644 app/assets/stylesheets/mobile/components/user-card.scss create mode 100644 test/javascripts/acceptance/user-card-mobile-test.js.es6 diff --git a/app/assets/javascripts/discourse/components/group-card-contents.js.es6 b/app/assets/javascripts/discourse/components/group-card-contents.js.es6 index 93f2b20260e..994e5533663 100644 --- a/app/assets/javascripts/discourse/components/group-card-contents.js.es6 +++ b/app/assets/javascripts/discourse/components/group-card-contents.js.es6 @@ -2,6 +2,7 @@ import { setting } from "discourse/lib/computed"; import { default as computed } from "ember-addons/ember-computed-decorators"; import CardContentsBase from "discourse/mixins/card-contents-base"; import CleansUp from "discourse/mixins/cleans-up"; +import { groupPath } from "discourse/lib/url"; const maxMembersToDisplay = 10; @@ -40,7 +41,7 @@ export default Ember.Component.extend(CardContentsBase, CleansUp, { @computed("group") groupPath(group) { - return `${Discourse.BaseUri}/g/${group.name}`; + return groupPath(group.name); }, _showCallback(username, $target) { @@ -88,6 +89,11 @@ export default Ember.Component.extend(CardContentsBase, CleansUp, { showGroup(group) { this.showGroup(group); this._close(); + }, + + showUser(user) { + this.showUser(user); + this._close(); } } }); diff --git a/app/assets/javascripts/discourse/components/user-card-contents.js.es6 b/app/assets/javascripts/discourse/components/user-card-contents.js.es6 index d3fb83de496..a3681637b5e 100644 --- a/app/assets/javascripts/discourse/components/user-card-contents.js.es6 +++ b/app/assets/javascripts/discourse/components/user-card-contents.js.es6 @@ -205,8 +205,8 @@ export default Ember.Component.extend( this._close(); }, - showUser() { - this.showUser(this.get("user")); + showUser(username) { + this.showUser(username); this._close(); }, diff --git a/app/assets/javascripts/discourse/controllers/user-card.js.es6 b/app/assets/javascripts/discourse/controllers/user-card.js.es6 index 3628989e31f..b5d0ba39fee 100644 --- a/app/assets/javascripts/discourse/controllers/user-card.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-card.js.es6 @@ -1,3 +1,9 @@ +import { + default as DiscourseURL, + userPath, + groupPath +} from "discourse/lib/url"; + export default Ember.Controller.extend({ topic: Ember.inject.controller(), application: Ember.inject.controller(), @@ -9,7 +15,11 @@ export default Ember.Controller.extend({ }, showUser(user) { - this.transitionToRoute("user", user); + DiscourseURL.routeTo(userPath(user.username_lower)); + }, + + showGroup(group) { + DiscourseURL.routeTo(groupPath(group.name)); } } }); diff --git a/app/assets/javascripts/discourse/lib/url.js.es6 b/app/assets/javascripts/discourse/lib/url.js.es6 index 3c13dbc091a..37328433461 100644 --- a/app/assets/javascripts/discourse/lib/url.js.es6 +++ b/app/assets/javascripts/discourse/lib/url.js.es6 @@ -52,6 +52,10 @@ export function userPath(subPath) { return Discourse.getURL(subPath ? `/u/${subPath}` : "/u"); } +export function groupPath(subPath) { + return Discourse.getURL(subPath ? `/g/${subPath}` : "/g"); +} + let _jumpScheduled = false; export function jumpToElement(elementId) { if (_jumpScheduled || Ember.isEmpty(elementId)) { diff --git a/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 b/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 index 756a24930f8..1c4909d04a2 100644 --- a/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 +++ b/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 @@ -26,8 +26,8 @@ export default Ember.Mixin.create({ username = Ember.Handlebars.Utils.escapeExpression(username.toString()); - // Don't show on mobile or nested - if (this.site.mobileView || $target.parents(".card-content").length) { + // Don't show if nested + if ($target.parents(".card-content").length) { this._close(); DiscourseURL.routeTo($target.attr("href")); return false; @@ -97,10 +97,6 @@ export default Ember.Mixin.create({ } this._close(); - - if (this.site.mobileView) { - return false; - } } return true; @@ -149,58 +145,67 @@ export default Ember.Mixin.create({ Ember.run.schedule("afterRender", () => { if (target) { - let position = target.offset(); - if (position) { - position.bottom = "unset"; + if (!this.site.mobileView) { + let position = target.offset(); + if (position) { + position.bottom = "unset"; - if (rtl) { - // The site direction is rtl - position.right = $(window).width() - position.left + 10; - position.left = "auto"; - let overage = $(window).width() - 50 - (position.right + width); - if (overage < 0) { - position.right += overage; - position.top += target.height() + 48; - verticalAdjustments += target.height() + 48; - } - } else { - // The site direction is ltr - position.left += target.width() + 10; - - let overage = $(window).width() - 50 - (position.left + width); - if (overage < 0) { - position.left += overage; - position.top += target.height() + 48; - verticalAdjustments += target.height() + 48; - } - } - - position.top -= $("#main-outlet").offset().top; - if (isFixed) { - position.top -= $("html").scrollTop(); - //if content is fixed and will be cut off on the bottom, display it above... - if ( - position.top + height + verticalAdjustments > - $(window).height() - 50 - ) { - position.bottom = - $(window).height() - - (target.offset().top - $("html").scrollTop()); - if (verticalAdjustments > 0) { - position.bottom += 48; + if (rtl) { + // The site direction is rtl + position.right = $(window).width() - position.left + 10; + position.left = "auto"; + let overage = $(window).width() - 50 - (position.right + width); + if (overage < 0) { + position.right += overage; + position.top += target.height() + 48; + verticalAdjustments += target.height() + 48; + } + } else { + // The site direction is ltr + position.left += target.width() + 10; + + let overage = $(window).width() - 50 - (position.left + width); + if (overage < 0) { + position.left += overage; + position.top += target.height() + 48; + verticalAdjustments += target.height() + 48; } - position.top = "unset"; } - } - const avatarOverflowSize = 44; - if (isDocked && position.top < avatarOverflowSize) { - position.top = avatarOverflowSize; - } + position.top -= $("#main-outlet").offset().top; + if (isFixed) { + position.top -= $("html").scrollTop(); + //if content is fixed and will be cut off on the bottom, display it above... + if ( + position.top + height + verticalAdjustments > + $(window).height() - 50 + ) { + position.bottom = + $(window).height() - + (target.offset().top - $("html").scrollTop()); + if (verticalAdjustments > 0) { + position.bottom += 48; + } + position.top = "unset"; + } + } - this.$().css(position); + const avatarOverflowSize = 44; + if (isDocked && position.top < avatarOverflowSize) { + position.top = avatarOverflowSize; + } + + this.$().css(position); + } } + if (this.site.mobileView) { + $(".card-cloak").removeClass("hidden"); + let position = target.offset(); + position.top = "10%"; // match modal behaviour + position.left = 0; + this.$().css(position); + } this.$().toggleClass("docked-card", isDocked); // After the card is shown, focus on the first link @@ -216,6 +221,9 @@ export default Ember.Mixin.create({ _hide() { if (!this.get("visible")) { this.$().css({ left: -9999, top: -9999 }); + if (this.site.mobileView) { + $(".card-cloak").addClass("hidden"); + } } }, diff --git a/app/assets/javascripts/discourse/templates/components/group-card-contents.hbs b/app/assets/javascripts/discourse/templates/components/group-card-contents.hbs index f906f8ba549..164df0d599d 100644 --- a/app/assets/javascripts/discourse/templates/components/group-card-contents.hbs +++ b/app/assets/javascripts/discourse/templates/components/group-card-contents.hbs @@ -3,7 +3,7 @@