A platform for community discussion. Free, open, simple.
UX: Add quick link to edit own profile from user card (#36048)
Penar Musarajda01676372cc
diff --git a/app/assets/stylesheets/common/components/user-card.scss b/app/assets/stylesheets/common/components/user-card.scssindex 2ea8c971588..48b0c538615 100644--- a/app/assets/stylesheets/common/components/user-card.scss+++ b/app/assets/stylesheets/common/components/user-card.scss@@ -187,6 +187,38 @@.user-card-avatar {margin-top: var(--avatar-margin);max-height: var(--avatar-width);+ position: relative;++ .own-avatar-pencil {+ opacity: 0;+ position: absolute;+ width: 80%;+ height: 80%;+ border-radius: 50%;+ right: 0%;+ bottom: 0%;+ font-size: 1.25rem;+ display: flex;+ justify-content: center;+ align-items: center;+ transition: opacity 0.2s;++ .d-icon {+ position: inherit;+ position: absolute;+ bottom: 0%;+ right: 0%;+ background-color: rgb(var(--secondary-rgb), 1);+ border-radius: 50%;+ padding: 0.5rem;+ color: var(--primary);+ box-shadow: var(--shadow-dropdown);+ }++ &:hover {+ opacity: 0.9;+ }+ }}.avatar {diff --git a/frontend/discourse/app/components/user-card-contents.gjs b/frontend/discourse/app/components/user-card-contents.gjsindex 0a6ed09431d..a778ecadffa 100644--- a/frontend/discourse/app/components/user-card-contents.gjs+++ b/frontend/discourse/app/components/user-card-contents.gjs@@ -91,6 +91,19 @@ export default class UserCardContents extends CardContentsBase {return this.user.name !== this.user.username;}+ @computed("user.id", "currentUser.id")+ get isOwnCard() {+ return this.currentUser && this.user.id === this.currentUser.id;+ }++ @computed("user.username_lower", "isOwnCard")+ get avatarUrl() {+ if (this.isOwnCard) {+ return `/u/${this.user.username_lower}/preferences/account`;+ }+ return this.user.path;+ }+@computed("model.id", "currentUser.id")get canCheckEmails() {return new CanCheckEmailsHelper(@@ -382,11 +395,17 @@ export default class UserCardContents extends CardContentsBase {}}</span>{{else}}<a- {{on "click" this.handleShowUser}}- href={{this.user.path}}+ href={{this.avatarUrl}}class="card-huge-avatar"tabindex="-1"- >{{boundAvatar this.user "huge"}}</a>+ >+ {{#if this.isOwnCard}}+ <span class="own-avatar-pencil">+ {{icon "pencil"}}+ </span>+ {{/if}}+ {{boundAvatar this.user "huge"}}+ </a>{{/if}}<UserAvatarFlair @user={{this.user}} />diff --git a/frontend/discourse/tests/acceptance/user-card-test.js b/frontend/discourse/tests/acceptance/user-card-test.jsindex 5935aa4e37a..d2e801b8e32 100644--- a/frontend/discourse/tests/acceptance/user-card-test.js+++ b/frontend/discourse/tests/acceptance/user-card-test.js@@ -240,3 +240,33 @@ acceptance("User Card - Restricted reason HTML", function (needs) {);});});++acceptance("User Card - Edit Profile Button", function (needs) {+ needs.user();++ test("shows edit profile button when viewing own card", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click(".topic-map__users-trigger");+ await click('a[data-user-card="eviltrout"]');++ assert.dom(".user-card .own-avatar-pencil").exists();+ assert+ .dom(".user-card .user-card-avatar > a")+ .hasProperty(+ "href",+ /\/u\/eviltrout\/preferences\/account$/,+ "links to account preferences"+ );+ });++ test("does not show edit profile button when viewing another user's card", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click(".topic-map__users-trigger");+ await click('a[data-user-card="charlie"]');++ assert.dom(".user-card .own-avatar-pencil").doesNotExist();+ assert+ .dom(".user-card .user-card-avatar > a")+ .hasProperty("href", /\/u\/charlie$/, "links to profile");+ });+});