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

View file

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