Merge pull request #15037 from ramonlsouza/userlist-throttle

fix: userlist throttle instead of debounce
This commit is contained in:
Anton Georgiev 2022-05-18 15:21:14 -04:00 committed by GitHub
commit a7fc4811bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -1,8 +1,10 @@
import { useState, useContext, useEffect } from 'react';
import {
useState, useContext, useRef, useEffect,
} from 'react';
import { UsersContext } from '/imports/ui/components/components-data/users-context/context';
import { throttle } from 'lodash';
const USER_JOIN_UPDATE_TIMEOUT = 1000;
let updateTimeout = null;
const USER_JOIN_UPDATE_THROTTLE_TIME = 1000;
export default function useContextUsers() {
const usingUsersContext = useContext(UsersContext);
@ -11,17 +13,15 @@ export default function useContextUsers() {
const [users, setUsers] = useState(null);
const [isReady, setIsReady] = useState(true);
const throttledSetUsers = useRef(throttle(() => {
setUsers(contextUsers);
setIsReady(true);
},
USER_JOIN_UPDATE_THROTTLE_TIME, { trailing: true }));
useEffect(() => {
setIsReady(false);
if (updateTimeout) {
clearTimeout(updateTimeout);
}
updateTimeout = setTimeout(() => {
setUsers(contextUsers);
setIsReady(true);
}, USER_JOIN_UPDATE_TIMEOUT);
throttledSetUsers.current();
}, [contextUsers]);
return {

View File

@ -22,9 +22,9 @@ const UserParticipantsContainer = (props) => {
const { videoUsers, whiteboardUsers } = props;
const { users: contextUsers, isReady } = useContextUsers();
const currentUser = contextUsers ? contextUsers[Auth.meetingID][Auth.userID] : null;
const usersArray = contextUsers ? Object.values(contextUsers[Auth.meetingID]) : null;
const users = contextUsers ? formatUsers(usersArray, videoUsers, whiteboardUsers) : [];
const currentUser = contextUsers && isReady ? contextUsers[Auth.meetingID][Auth.userID] : null;
const usersArray = contextUsers && isReady ? Object.values(contextUsers[Auth.meetingID]) : null;
const users = contextUsers && isReady ? formatUsers(usersArray, videoUsers, whiteboardUsers) : [];
return (
<UserParticipants {