Skip to content

Commit

Permalink
Removed API Call to fetch status of user
Browse files Browse the repository at this point in the history
  • Loading branch information
dhairyashiil committed Jan 6, 2025
1 parent d1d4716 commit 27dcbe6
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions packages/react/src/views/RoomMembers/RoomMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const RoomMembers = ({ members }) => {
const [searchTerm, setSearchTerm] = useState('');
const [filteredMembers, setFilteredMembers] = useState(members);

const [statusData, setStatusData] = useState({});
const [viewStatus, setViewStatus] = useState('All');

useEffect(() => {
Expand All @@ -57,37 +56,10 @@ const RoomMembers = ({ members }) => {
getUserInfo();
}, [RCInstance]);

useEffect(() => {
const fetchStatuses = async () => {
const statusPromises = members.map(async (member) => {
try {
const res = await RCInstance.getUserStatus(member._id);
if (res.success) {
return { id: member._id, status: res.status };
}
} catch (err) {
console.error('Error fetching user status:', err);
}
return { id: member._id, status: 'offline' };
});

const statuses = await Promise.all(statusPromises);

const statusMap = statuses.reduce((acc, { id, status }) => {
acc[id] = status;
return acc;
}, {});

setStatusData(statusMap);
};

fetchStatuses();
}, [members, RCInstance]);

useEffect(() => {
const filtered = members.filter((member) => {
if (viewStatus === 'Online') {
return statusData[member._id] === 'online';
return member.status === 'online';
}
return true;
});
Expand All @@ -99,7 +71,7 @@ const RoomMembers = ({ members }) => {
member.username?.toLowerCase().includes(searchTerm.toLowerCase())
)
);
}, [viewStatus, statusData, searchTerm, members]);
}, [viewStatus, searchTerm, members]);

const roles = userInfo && userInfo.roles ? userInfo.roles : [];
const isAdmin = roles.includes('admin');
Expand All @@ -109,7 +81,6 @@ const RoomMembers = ({ members }) => {
setViewStatus(value);
};

// const totalMembers = members.length;
const displayedMembers = filteredMembers.length;

return (
Expand Down Expand Up @@ -200,7 +171,7 @@ const RoomMembers = ({ members }) => {
<RoomMemberItem
user={member}
host={host}
userStatus={statusData[member._id]}
userStatus={member.status}
key={member._id}
/>
))
Expand Down

0 comments on commit 27dcbe6

Please sign in to comment.