From 84b10d072a21ec8b7ebde3f78e3e1bfb71196914 Mon Sep 17 00:00:00 2001 From: Joe McGrath Date: Mon, 7 Feb 2022 15:57:10 +0900 Subject: [PATCH] feat(friends): display outgoing requests after send --- components/views/friends/add/Add.vue | 12 +++--- components/views/friends/friend/Friend.html | 12 ++++++ components/views/friends/friend/Friend.vue | 8 +++- cypress | 2 +- locales/en-US.js | 4 +- pages/friends/list/FriendsList.html | 47 +++++++++++++++------ store/friends/actions.ts | 26 ++++++++---- types/ui/friends.d.ts | 2 +- 8 files changed, 83 insertions(+), 30 deletions(-) diff --git a/components/views/friends/add/Add.vue b/components/views/friends/add/Add.vue index c3077cae65..be273fe744 100644 --- a/components/views/friends/add/Add.vue +++ b/components/views/friends/add/Add.vue @@ -34,6 +34,12 @@ export default Vue.extend({ return `${location.origin}/#/friends/list/${this.accounts.active}` }, }, + mounted() { + if (this.$route.params && this.$route.params.id) { + this.$data.accountID = this.$route.params.id + this._searchFriend() + } + }, methods: { _searchFriend: debounce(async function (this: any) { if (this.accountID.length >= 40) { @@ -95,12 +101,6 @@ export default Vue.extend({ } }, }, - mounted() { - if (this.$route.params && this.$route.params.id) { - this.$data.accountID = this.$route.params.id - this._searchFriend() - } - }, }) diff --git a/components/views/friends/friend/Friend.html b/components/views/friends/friend/Friend.html index 769fb7bcb7..02e5da23d6 100644 --- a/components/views/friends/friend/Friend.html +++ b/components/views/friends/friend/Friend.html @@ -52,6 +52,18 @@ +
+ + + +
, - default: () => {}, + required: true, }, request: { type: Boolean, @@ -51,6 +51,10 @@ export default Vue.extend({ type: Boolean, default: false, }, + outgoing: { + type: Boolean, + default: false, + }, }, data() { return { @@ -117,6 +121,8 @@ export default Vue.extend({ this.loading = AddFriendEnum.EMPTY } }, + // todo - remove friend request for both users on click + async cancelRequest() {}, sendMessageRequest() { this.$router.push(`/chat/direct/${this.$props.friend.address}`) }, diff --git a/cypress b/cypress index 04f0fac5f2..7eb9ca784a 160000 --- a/cypress +++ b/cypress @@ -1 +1 @@ -Subproject commit 04f0fac5f2a56db752b7b4ea61e932e519c2dee7 +Subproject commit 7eb9ca784a65ed982a6ed407839863832827fd03 diff --git a/locales/en-US.js b/locales/en-US.js index 0cafb5e3ee..d6210a8406 100644 --- a/locales/en-US.js +++ b/locales/en-US.js @@ -528,7 +528,8 @@ export default { not_found: "Hmm, we couldn't find a user at that address", invalid_id: 'Invalid account ID', request_sent: 'Friend request successfully sent!', - requests: 'Friends request', + requests: 'Friend requests', + outgoing: 'Outgoing requests', blocked: 'Blocked friends', search_placeholder: 'Some User...', add: 'Add Friend', @@ -546,6 +547,7 @@ export default { send: 'Send', message: 'Message', options: 'Options', + cancel: 'Cancel request', }, market_place: { title: 'Marketplace', diff --git a/pages/friends/list/FriendsList.html b/pages/friends/list/FriendsList.html index ebd13f1d53..57f6d56134 100644 --- a/pages/friends/list/FriendsList.html +++ b/pages/friends/list/FriendsList.html @@ -6,24 +6,47 @@ -
- -
- +
+ +
+ + :key="friend.from" + request + /> + + +
diff --git a/store/friends/actions.ts b/store/friends/actions.ts index 991eb97a58..4d59a6492d 100644 --- a/store/friends/actions.ts +++ b/store/friends/actions.ts @@ -53,8 +53,11 @@ export default { }), ) - const outgoingRequests = outgoing.map((account) => - friendAccountToOutgoingRequest(account), + const outgoingRequests = await Promise.all( + outgoing.map(async (account) => { + const userInfo = await serverProgram.getUser(new PublicKey(account.to)) + return friendAccountToOutgoingRequest(account, userInfo) + }), ) commit('setIncomingRequests', incomingRequests) @@ -130,7 +133,7 @@ export default { throw new Error(FriendsError.FRIEND_INFO_NOT_FOUND) } - const friend: Omit = { + const friend: Omit = { account: friendAccount, name: rawUser.name, profilePicture: rawUser.photoHash, @@ -161,7 +164,7 @@ export default { ) commit( 'removeOutgoingRequest', - friendAccountToOutgoingRequest(friendAccount).requestId, + friendAccountToOutgoingRequest(friendAccount, null).requestId, ) return } @@ -212,7 +215,7 @@ export default { if (account) { commit( 'removeOutgoingRequest', - friendAccountToOutgoingRequest(account).requestId, + friendAccountToOutgoingRequest(account, null).requestId, ) } }) @@ -254,6 +257,7 @@ export default { const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager const $Crypto: Crypto = Vue.prototype.$Crypto const $TextileManager: TextileManager = Vue.prototype.$TextileManager + const serverProgram: ServerProgram = new ServerProgram($SolanaManager) const textilePublicKey = $TextileManager.getIdentityPublicKey() @@ -342,11 +346,15 @@ export default { friendAccountKey, ) - if (parsedFriendRequest) + if (parsedFriendRequest) { + const userInfo = await serverProgram.getUser( + new PublicKey(parsedFriendRequest.to), + ) commit( 'addOutgoingRequest', - friendAccountToOutgoingRequest(parsedFriendRequest), + friendAccountToOutgoingRequest(parsedFriendRequest, userInfo), ) + } } }, /** @@ -509,7 +517,7 @@ export default { if (transactionId) { commit( 'removeOutgoingRequest', - friendAccountToOutgoingRequest(account).requestId, + friendAccountToOutgoingRequest(account, null).requestId, ) } }, @@ -579,11 +587,13 @@ function friendAccountToIncomingRequest( */ function friendAccountToOutgoingRequest( friendAccount: FriendAccount, + userInfo: RawUser | null, ): OutgoingRequest { return { requestId: friendAccount.accountId, to: friendAccount.to, account: friendAccount, pending: false, + userInfo, } } diff --git a/types/ui/friends.d.ts b/types/ui/friends.d.ts index 3a26c17083..ef4b518042 100644 --- a/types/ui/friends.d.ts +++ b/types/ui/friends.d.ts @@ -9,11 +9,11 @@ export interface FriendRequest { requestId: string account: FriendAccount pending: boolean + userInfo: RawUser | null } export interface IncomingRequest extends FriendRequest { from: string - userInfo: RawUser | null account: FriendAccount }