Fix member load triggering re-renders (#261)

Signed-off-by: ajbura <ajbura@gmail.com>
This commit is contained in:
ajbura 2022-02-13 13:32:57 +05:30
parent 8ddbc24dd4
commit 278fd5bd59
2 changed files with 8 additions and 3 deletions

View file

@ -58,8 +58,10 @@ function useMemberOfMembership(roomId, membership) {
useEffect(() => { useEffect(() => {
let isMounted = true; let isMounted = true;
let isLoadingMembers = false;
const updateMemberList = (event) => { const updateMemberList = (event) => {
if (isLoadingMembers) return;
if (event && event?.getRoomId() !== roomId) return; if (event && event?.getRoomId() !== roomId) return;
const memberOfMembership = normalizeMembers( const memberOfMembership = normalizeMembers(
room.getMembersWithMembership(membership) room.getMembersWithMembership(membership)
@ -69,7 +71,9 @@ function useMemberOfMembership(roomId, membership) {
}; };
updateMemberList(); updateMemberList();
isLoadingMembers = true;
room.loadMembersIfNeeded().then(() => { room.loadMembersIfNeeded().then(() => {
isLoadingMembers = false;
if (!isMounted) return; if (!isMounted) return;
updateMemberList(); updateMemberList();
}); });

View file

@ -103,10 +103,10 @@ function PeopleDrawer({ roomId }) {
}, [memberList]); }, [memberList]);
useEffect(() => { useEffect(() => {
let isGettingMembers = true; let isLoadingMembers = false;
let isRoomChanged = false; let isRoomChanged = false;
const updateMemberList = (event) => { const updateMemberList = (event) => {
if (isGettingMembers) return; if (isLoadingMembers) return;
if (event && event?.getRoomId() !== roomId) return; if (event && event?.getRoomId() !== roomId) return;
setMemberList( setMemberList(
simplyfiMembers( simplyfiMembers(
@ -117,8 +117,9 @@ function PeopleDrawer({ roomId }) {
}; };
searchRef.current.value = ''; searchRef.current.value = '';
updateMemberList(); updateMemberList();
isLoadingMembers = true;
room.loadMembersIfNeeded().then(() => { room.loadMembersIfNeeded().then(() => {
isGettingMembers = false; isLoadingMembers = false;
if (isRoomChanged) return; if (isRoomChanged) return;
updateMemberList(); updateMemberList();
}); });