|
@@ -12,11 +12,12 @@ import shortid from 'shortid';
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
|
|
import AlertInfo from '../../../reusableComponents/AlertInfo'
|
|
|
-import doubleCheck from '../../../../img/clipart289625.png'
|
|
|
+import DoneAllIcon from '@mui/icons-material/DoneAll';
|
|
|
import { firstLetter, slicedWord, timeStamp } from '../../../../helpers'
|
|
|
import { getState } from '../../../../redux/chats/selector'
|
|
|
import { asyncGetChats } from '../../../../redux/chats/operations'
|
|
|
import { asyncStartChatById } from '../../../../redux/chat/operations'
|
|
|
+import { actionScroll } from '../../../../redux/control/action'
|
|
|
|
|
|
const StyledBadge = styled(Badge)(({ theme }) => ({
|
|
|
'& .MuiBadge-badge': {
|
|
@@ -163,19 +164,22 @@ const ChatsList = () => {
|
|
|
const { total, chats , lastMessages,lastOnline } = useSelector(getState)
|
|
|
|
|
|
|
|
|
- const handleListItemClick = async (i: number, companionId: string) => {
|
|
|
- await dispatch(asyncStartChatById(companionId))
|
|
|
- setSelectedIndex(i);
|
|
|
+ const handleListItemClick = (i: number, companionId: string) => {
|
|
|
+ dispatch(asyncStartChatById(companionId))
|
|
|
+ dispatch(actionScroll(false))
|
|
|
+ setSelectedIndex(i);
|
|
|
}
|
|
|
|
|
|
- const handleNewMsgS = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, i: number) => {
|
|
|
+ const handleNewMsgS = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, i: number,companionId: string) => {
|
|
|
e.stopPropagation()
|
|
|
+ dispatch(asyncStartChatById(companionId))
|
|
|
+ dispatch(actionScroll(true))
|
|
|
console.log(i,'index','clicked read new messages')
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
const handleReset = () => dispatch(asyncGetChats())
|
|
|
- const idInterval = setInterval(handleReset, 10000);
|
|
|
+ const idInterval = setInterval(handleReset, 1500);
|
|
|
return () => clearInterval(idInterval);
|
|
|
}, [dispatch]);
|
|
|
|
|
@@ -187,7 +191,7 @@ const ChatsList = () => {
|
|
|
return total !== '0' ? (
|
|
|
<List className={classes.list} component="nav"
|
|
|
aria-label="main mailbox folders">
|
|
|
- {chats.map(({name, lastName, avatarUrl, updatedAt, color,companionId,mute }, i: number) =>
|
|
|
+ {chats.map(({name, lastName, avatarUrl, updatedAt, color,companionId,mute,seen,total }, i: number) =>
|
|
|
<ListItemButton
|
|
|
key={shortid.generate()}
|
|
|
selected={selectedIndex === i}
|
|
@@ -210,13 +214,13 @@ const ChatsList = () => {
|
|
|
`${firstLetter(name)}${slicedWord(name, 8, 1)} joined Telegram`} />
|
|
|
<ListItemIcon className={classes.listItem_iconRight}>
|
|
|
<div className={classes.listItem_iconTimeChecked}>
|
|
|
- <img alt='double check' width="16" height='16' src={doubleCheck} />
|
|
|
+ {total-seen === 0 && <DoneAllIcon style={{ color: '#18bd03' }} fontSize='small' />}
|
|
|
<Typography className={classes.listItem_icon_time} variant="h6" color="initial">
|
|
|
{lastMessages[i] ? timeStamp(lastMessages[i].updatedAt) :
|
|
|
timeStamp(updatedAt)}</Typography>
|
|
|
</div>
|
|
|
- {lastMessages[i] ? <button onClick={(e) => handleNewMsgS(e, i)}
|
|
|
- className={mute?classes.listItem_iconRightBtnMute:classes.listItem_iconRightBtn}>0</button> :
|
|
|
+ {lastMessages[i] && total > seen ? <button onClick={(e) => handleNewMsgS(e, i,companionId)}
|
|
|
+ className={mute?classes.listItem_iconRightBtnMute:classes.listItem_iconRightBtn}>{total-seen}</button> :
|
|
|
<button className={classes.listItem_iconRightBtnHidden}/>}
|
|
|
</ListItemIcon>
|
|
|
</ListItemButton>)}
|