-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SK-194 implemented typing status indicator (#126)
* SK-194 added names view * SK-194 added support name in last message view * SK-194 added validation for system message * SK-194 updated last message structure * SK-194 fixed error on close chat info * SK-194 minor fixed * SK-194 fixed user name view, cut if length > 8 * SK-194 fixed last message user name view (nowrap)
- Loading branch information
1 parent
3cfc2bb
commit 3ecf02d
Showing
13 changed files
with
208 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ThreeDots } from "react-loader-spinner"; | ||
|
||
export default function DotsLoader({ width, height, mainColor }) { | ||
return ( | ||
<ThreeDots | ||
visible={true} | ||
height={width} | ||
width={height} | ||
color={mainColor || " var(--color-accent-dark)"} | ||
radius="9" | ||
ariaLabel="three-dots-loading" | ||
wrapperStyle={{}} | ||
wrapperClass={"typing-dots"} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import DotsLoader from "./DotsLoader"; | ||
import getLastMessageUserName from "@utils/user/get_last_message_user_name"; | ||
import { selectParticipantsEntities } from "@src/store/values/Participants"; | ||
import { useMemo } from "react"; | ||
import { useSelector } from "react-redux"; | ||
|
||
export default function TypingLine({ userIds, displayUserNames = false }) { | ||
console.log(userIds); | ||
const participants = useSelector(selectParticipantsEntities); | ||
|
||
const usersNameView = useMemo(() => { | ||
if (!displayUserNames) { | ||
return null; | ||
} | ||
|
||
const typingUsers = userIds?.map((id) => participants[id]); | ||
const typingUsersLength = typingUsers?.length; | ||
|
||
if (typingUsersLength > 2) { | ||
return `${getLastMessageUserName(typingUsers[0])} and ${ | ||
typingUsersLength - 1 | ||
} more `; | ||
} | ||
|
||
return typingUsers?.map( | ||
(user, i) => | ||
`${getLastMessageUserName(user)}${ | ||
i !== typingUsersLength - 1 ? ", " : " " | ||
}` | ||
); | ||
}, [participants, userIds, displayUserNames]); | ||
|
||
return ( | ||
<div className="typing-line__container"> | ||
<DotsLoader height={22} width={16} /> | ||
<p>{usersNameView}typing</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const cut = (text) => (text.length > 8 ? text.slice(0, 6) + "..." : text); | ||
|
||
export default function getLastMessageUserName(userObject) { | ||
if (!userObject) { | ||
return null; | ||
} | ||
|
||
const { first_name, last_name, login } = userObject; | ||
|
||
if (!first_name && !last_name) { | ||
return login ? cut(login[0].toUpperCase() + login.slice(1)) : undefined; | ||
} | ||
|
||
const fullName = [first_name, last_name].filter(Boolean).join(" "); | ||
|
||
return last_name && fullName.length <= 10 ? fullName : cut(first_name); | ||
} |