Merge pull request #15037 from ramonlsouza/userlist-throttle
fix: userlist throttle instead of debounce
This commit is contained in:
commit
a7fc4811bb
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user