diff options
author | Cyrille Bollu <cyrpub@bollu.be> | 2019-10-25 13:26:16 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-10-13 23:54:14 +0200 |
commit | f0970a19d8ea3e9a4888f2dc28998b536009b21f (patch) | |
tree | 19b4c1b01aaf7266c4277afdf9969fec921d83bc | |
parent | d8792993d4ebf3bb545508a2174a16d68c82b74c (diff) |
FIX: Uses computed properties rather than methods for the account mixins.
Signed-off-by: Cyrille Bollu <cyrpub@bollu.be>
-rw-r--r-- | src/components/FollowButton.vue | 6 | ||||
-rw-r--r-- | src/components/ProfileInfo.vue | 26 | ||||
-rw-r--r-- | src/mixins/accountMixins.js | 28 | ||||
-rw-r--r-- | src/views/TimelineSinglePost.vue | 12 |
4 files changed, 34 insertions, 38 deletions
diff --git a/src/components/FollowButton.vue b/src/components/FollowButton.vue index b4d34664..73f6704c 100644 --- a/src/components/FollowButton.vue +++ b/src/components/FollowButton.vue @@ -22,7 +22,7 @@ <template> <!-- Show button only if user is authenticated and she is not the same as the account viewed --> - <div v-if="!serverData.public && accountInfo(account) && accountInfo(account).viewerLink!='viewer'"> + <div v-if="!serverData.public && accountInfo && accountInfo.viewerLink!='viewer'"> <button v-if="isCurrentUserFollowing" :class="{'icon-loading-small': followLoading}" @click="unfollow()" @mouseover="followingText=t('social', 'Unfollow')" @mouseleave="followingText=t('social', 'Following')"> @@ -49,6 +49,10 @@ export default { account: { type: String, default: '' + }, + uid: { + type: String, + default: '' } }, data: function() { diff --git a/src/components/ProfileInfo.vue b/src/components/ProfileInfo.vue index f7392e84..899494a2 100644 --- a/src/components/ProfileInfo.vue +++ b/src/components/ProfileInfo.vue @@ -21,26 +21,26 @@ --> <template> - <div v-if="profileAccount(uid) && accountInfo(uid)" class="user-profile"> + <div v-if="profileAccount && accountInfo" class="user-profile"> <div> - <avatar v-if="accountInfo(uid).local" :user="localUid" :disable-tooltip="true" + <avatar v-if="accountInfo.local" :user="localUid" :disable-tooltip="true" :size="128" /> <avatar v-else :url="avatarUrl" :disable-tooltip="true" :size="128" /> <h2>{{ displayName }}</h2> - <p>@{{ accountInfo(uid).account }}</p> - <p v-if="accountInfo(uid).website"> - Website: <a :href="accountInfo(uid).website.value"> - {{ accountInfo(uid).website.value }} + <p>@{{ accountInfo.account }}</p> + <p v-if="accountInfo.website"> + Website: <a :href="accountInfo.website.value"> + {{ accountInfo.website.value }} </a> </p> - <follow-button :account="accountInfo(uid).account" /> + <follow-button :account="accountInfo.account" :uid="uid" /> <button v-if="serverData.public" class="primary" @click="followRemote"> {{ t('social', 'Follow') }} </button> </div> <!-- TODO: we have no details, timeline and follower list for non-local accounts for now --> - <ul v-if="accountInfo(uid).details && accountInfo(uid).local" class="user-profile--sections"> + <ul v-if="accountInfo.details && accountInfo.local" class="user-profile--sections"> <li> <router-link :to="{ name: 'profile', params: { account: uid } }" class="icon-category-monitoring"> {{ getCount('post') }} {{ t('social', 'posts') }} @@ -133,20 +133,20 @@ export default { return (this.uid.indexOf('@') === -1) ? this.uid : this.uid.substr(0, this.uid.indexOf('@')) }, displayName() { - if (typeof this.accountInfo(this.uid).name !== 'undefined' && this.accountInfo(this.uid).name !== '') { - return this.accountInfo(this.uid).name + if (typeof this.accountInfo.name !== 'undefined' && this.accountInfo.name !== '') { + return this.accountInfo.name } if (typeof this.accountInfo.preferredUsername !== 'undefined' && this.accountInfo.preferredUsername !== '') { return this.accountInfo.preferredUsername } - return this.profileAccount(this.uid) + return this.profileAccount }, getCount() { - let account = this.accountInfo(this.uid) + let account = this.accountInfo return (field) => account.details.count ? account.details.count[field] : '' }, avatarUrl() { - return generateUrl('/apps/social/api/v1/global/actor/avatar?id=' + this.accountInfo(this.uid).id) + return generateUrl('/apps/social/api/v1/global/actor/avatar?id=' + this.accountInfo.id) } }, methods: { diff --git a/src/mixins/accountMixins.js b/src/mixins/accountMixins.js index 9384aac6..cb312420 100644 --- a/src/mixins/accountMixins.js +++ b/src/mixins/accountMixins.js @@ -5,6 +5,8 @@ * * @license GNU AGPL version 3 or any later version * + * @file provides global account related methods + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the @@ -20,29 +22,25 @@ * */ -/* - * This file provides global account related methods - */ - import serverData from './serverData' export default { mixins: [ serverData ], - methods: { - // Returns the complete account name - profileAccount(uid) { - return (uid.indexOf('@') === -1) ? uid + '@' + this.hostname : uid + computed: { + /** @function Returns the complete account name */ + profileAccount() { + return (this.uid.indexOf('@') === -1) ? this.uid + '@' + this.hostname : this.uid }, - // Returns detailed information about an account (account must be loaded in the store first) - accountInfo(uid) { - return this.$store.getters.getAccount(this.profileAccount(uid)) + /** @functions Returns detailed information about an account (account must be loaded in the store first) */ + accountInfo() { + return this.$store.getters.getAccount(this.profileAccount) }, - // Somewhat duplicate with accountInfo(), but needed (for some reason) to avoid glitches - // where components would first show "user not found" before display an account's account info - accountLoaded(uid) { - return this.$store.getters.accountLoaded(this.profileAccount(uid)) + /** @function Somewhat duplicate with accountInfo(), but needed (for some reason) to avoid glitches + * where components would first show "user not found" before display an account's account info */ + accountLoaded() { + return this.$store.getters.accountLoaded(this.profileAccount) } } } diff --git a/src/views/TimelineSinglePost.vue b/src/views/TimelineSinglePost.vue index bbb271a4..42b350e4 100644 --- a/src/views/TimelineSinglePost.vue +++ b/src/views/TimelineSinglePost.vue @@ -46,33 +46,27 @@ export default { data() { return { mainPost: {}, - uid: this.account + uid: this.$route.params.account } }, computed: { /** * @description Tells whether Composer shall be displayed or not - * * @returns {boolean} - * */ composerDisplayStatus() { return this.$store.getters.getComposerDisplayStatus }, /** - * Extract the viewed account name from the URL - * + * @description Extracts the viewed account name from the URL * @returns {String} - * */ account() { return window.location.href.split('/')[window.location.href.split('/').length - 2].substr(1) }, /** - * Returns the timeline currently loaded in the store - * + * @description Returns the timeline currently loaded in the store * @returns {Object} - * */ timeline: function() { return this.$store.getters.getTimeline |