From 1cc427ba467000994de2fdcf144fc36ed09f341b Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 24 Oct 2017 09:58:45 +0100 Subject: [PATCH 1/2] Fix some react warnings in GroupMemberList - If the list contains two users twice, react would warn about duplicate keys. Use `index` instead. - Check if unmounted before setting state after fetching members. --- src/components/views/groups/GroupMemberList.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/views/groups/GroupMemberList.js b/src/components/views/groups/GroupMemberList.js index 511af37166..6cbbc968a7 100644 --- a/src/components/views/groups/GroupMemberList.js +++ b/src/components/views/groups/GroupMemberList.js @@ -59,6 +59,7 @@ export default withMatrixClient(React.createClass({ }, _fetchMembers: function() { + if (this._unmounted) return; this.setState({ members: this._groupStore.getGroupMembers(), invitedMembers: this._groupStore.getGroupInvitedMembers(), @@ -105,9 +106,9 @@ export default withMatrixClient(React.createClass({ }); } - memberList = memberList.map((m) => { + memberList = memberList.map((m, index) => { return ( - + ); }); From d1db0d6426ed04844d62a726df0c340e1ac5a6b2 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 24 Oct 2017 10:50:31 +0100 Subject: [PATCH 2/2] Deduplicate members, key by userId --- src/components/views/groups/GroupMemberList.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/views/groups/GroupMemberList.js b/src/components/views/groups/GroupMemberList.js index 6cbbc968a7..a5ab22eb0e 100644 --- a/src/components/views/groups/GroupMemberList.js +++ b/src/components/views/groups/GroupMemberList.js @@ -106,12 +106,11 @@ export default withMatrixClient(React.createClass({ }); } - memberList = memberList.map((m, index) => { - return ( - - ); + const uniqueMembers = {}; + memberList.forEach((m) => { + if (!uniqueMembers[m.userId]) uniqueMembers[m.userId] = m; }); - + memberList = Object.keys(uniqueMembers).map((userId) => uniqueMembers[userId]); memberList.sort((a, b) => { // TODO: should put admins at the top: we don't yet have that info if (a < b) { @@ -123,10 +122,16 @@ export default withMatrixClient(React.createClass({ } }); + const memberTiles = memberList.map((m) => { + return ( + + ); + }); + return - { memberList } + { memberTiles } ; },