Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing-display-fix #381

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions packages/react/src/components/TypingUsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,84 @@ export default function TypingUsers() {
}, [RCInstance, setTypingUsers, currentUserName]);

const typingStatusMessage = useMemo(() => {
if (typingUsers.length === 0) return '';
if (typingUsers.length === 1)
return (
<span>
<b>{typingUsers[0]}</b>
{' is typing...'}
</span>
);
if (typingUsers.length === 2)
if (!typingUsers.length) return '';

if (typingUsers.length) {
const otherTypingUsers = typingUsers.filter((user) => user !== currentUserName);

if (typingUsers.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have already filtered typingUsers, and stored the list in otherTypingUsers, the later variable should be used afterwards. However, I wonder why we need to refilter, when it is already done in useEffect. The issue might be somewhere else if its happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @abhinavkrin . Actually, the previous approach wasn't giving the correct output, which should be like - not to show that the "current user" is typing, and show it only when others are typing.

So, I had to resolve to use this manual approach of using if-else which covers all the cases. It works fine btw.

if (typingUsers.includes(currentUserName)) {
return '';
}
return (
<span>
<b>{typingUsers[0]}</b>
{' is typing...'}
</span>
);
}

if (typingUsers.length === 2) {
if (typingUsers.includes(currentUserName)) {
return (
<span>
<b>{otherTypingUsers[0]}</b>
{' is typing...'}
</span>
);
}
return (
<span>
<b>{typingUsers[0]}</b>
{' and '}
<b>{typingUsers[1]}</b>
{' are typing...'}
</span>
);
}

if (typingUsers.length === 3) {
if (typingUsers.includes(currentUserName)) {
return (
<span>
<b>{otherTypingUsers[0]}</b>
{' and '}
<b>{otherTypingUsers[1]}</b>
{' are typing...'}
</span>
);
}
return (
<span>
<b>{typingUsers[0]} </b>
{', '}
<b>{typingUsers[1]} </b>
{`and 1 more is typing...`}
umangutkarsh marked this conversation as resolved.
Show resolved Hide resolved
</span>
);
}

if (typingUsers.includes(currentUserName)) {
return (
<span>
<b>{typingUsers[0]} </b>
{', '}
<b>{typingUsers[1]} </b>
{`and ${typingUsers.length - 3} more are typing...`}
</span>
);
}
return (
<span>
<b>{typingUsers[0]}</b>
{' and '}
<b>{typingUsers[1]}</b>
{' are typing...'}
<b>{typingUsers[0]} </b>
{', '}
<b>{typingUsers[1]} </b>
{`and ${typingUsers.length - 2} more are typing...`}
</span>
);
return (
<span>
<b>{typingUsers[0]} </b>
{', '}
<b>{typingUsers[1]} </b>
{`and ${typingUsers.length - 2} more are typing...`}
</span>
);
}, [typingUsers]);
}

}, [typingUsers, currentUserName]);

return (
<Box
Expand Down