|
@@ -1,54 +1,18 @@
|
|
|
import List from '@mui/material/List';
|
|
|
-import ListItemButton from '@mui/material/ListItemButton';
|
|
|
-import Avatar from '@mui/material/Avatar';
|
|
|
-import ListItemText from '@mui/material/ListItemText';
|
|
|
-import ListItemIcon from '@mui/material/ListItemIcon';
|
|
|
-import { styled } from '@mui/material/styles';
|
|
|
-import Badge from '@mui/material/Badge';
|
|
|
-import VolumeOffIcon from '@mui/icons-material/VolumeOff';
|
|
|
-import { makeStyles, Typography } from '@material-ui/core'
|
|
|
+import { makeStyles } from '@material-ui/core'
|
|
|
import { useState,useEffect,useRef } from 'react';
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
|
|
import AlertInfo from '../../../reusableComponents/AlertInfo'
|
|
|
-import ContextMenuBar from './ContextMenuBar';
|
|
|
-import DoneAllIcon from '@mui/icons-material/DoneAll';
|
|
|
-import { firstLetter, slicedWord, timeStampEU,notification,playNotificationWithoutPermission } from '../../../../helpers'
|
|
|
+import ChatItem from './ChatItem';
|
|
|
+import { notification,playNotificationWithoutPermission } from '../../../../helpers'
|
|
|
import { getState } from '../../../../redux/chats/selector'
|
|
|
import { getChatMemo } from '../../../../redux/chat/selector'
|
|
|
import { asyncGetChats } from '../../../../redux/chats/operations'
|
|
|
import { asyncStartChatById } from '../../../../redux/chat/operations'
|
|
|
import { actionRemoveChat } from '../../../../redux/chat/action'
|
|
|
-import { actionScroll,actionIsOpen } from '../../../../redux/control/action'
|
|
|
-
|
|
|
-const StyledBadge = styled(Badge)(({ theme }) => ({
|
|
|
- '& .MuiBadge-badge': {
|
|
|
- backgroundColor: '#44b700',
|
|
|
- color: '#44b700',
|
|
|
- boxShadow: `0 0 0 2px ${theme.palette.background.paper}`,
|
|
|
- '&::after': {
|
|
|
- position: 'absolute',
|
|
|
- top: 0,
|
|
|
- left: 0,
|
|
|
- width: '100%',
|
|
|
- height: '100%',
|
|
|
- borderRadius: '50%',
|
|
|
- animation: 'ripple 1.2s infinite ease-in-out',
|
|
|
- border: '1px solid currentColor',
|
|
|
- content: '""',
|
|
|
- },
|
|
|
- },
|
|
|
- '@keyframes ripple': {
|
|
|
- '0%': {
|
|
|
- transform: 'scale(.8)',
|
|
|
- opacity: 1,
|
|
|
- },
|
|
|
- '100%': {
|
|
|
- transform: 'scale(2.4)',
|
|
|
- opacity: 0,
|
|
|
- },
|
|
|
- },
|
|
|
-}));
|
|
|
+import { actionScroll, actionIsOpen } from '../../../../redux/control/action'
|
|
|
+import { getIsOpen } from '../../../../redux/control/selector';
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
list: {
|
|
@@ -73,122 +37,21 @@ const useStyles = makeStyles({
|
|
|
backgroundColor: "#959595",
|
|
|
},
|
|
|
},
|
|
|
- listItemInnerText: {
|
|
|
- display: 'flex',
|
|
|
- alignContent: 'center',
|
|
|
- alignItems: 'center',
|
|
|
- flexWrap: 'nowrap',
|
|
|
- },
|
|
|
- listItemInnerText__icon: {
|
|
|
- marginLeft: 5,
|
|
|
- color: '#959595',
|
|
|
- },
|
|
|
- listItem_iconAvatar: {
|
|
|
- marginRight:10
|
|
|
- },
|
|
|
- listItem_iconRight: {
|
|
|
- marginRight: 10,
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- justifyContent: 'center',
|
|
|
- alignContent: 'center',
|
|
|
- flexDirection: 'column'
|
|
|
- },
|
|
|
- listItem_iconTimeChecked: {
|
|
|
- display: 'flex',
|
|
|
- flexWrap: 'nowrap',
|
|
|
- alignItems: 'center',
|
|
|
- justifyContent: 'center',
|
|
|
- alignContent: 'center',
|
|
|
- marginBottom:2
|
|
|
- },
|
|
|
- listItem_iconRightBtn: {
|
|
|
- background: '#0ac40a',
|
|
|
- borderRadius: '50%',
|
|
|
- color: '#ffffff',
|
|
|
- border: 'none',
|
|
|
- height: 24,
|
|
|
- width: 24,
|
|
|
- textAlign: 'center',
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- justifyContent: 'center',
|
|
|
- alignContent: 'center',
|
|
|
- fontSize: 12,
|
|
|
- marginLeft: 'auto',
|
|
|
- '&:hover': {
|
|
|
- outline: 'solid 3px #3ee415',
|
|
|
- }
|
|
|
- },
|
|
|
- listItem_iconRightBtnMute: {
|
|
|
- background: '#a7aaa7',
|
|
|
- borderRadius: '50%',
|
|
|
- color: '#ffffff',
|
|
|
- border: 'none',
|
|
|
- height: 24,
|
|
|
- width: 24,
|
|
|
- textAlign: 'center',
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- justifyContent: 'center',
|
|
|
- alignContent: 'center',
|
|
|
- fontSize: 12,
|
|
|
- marginLeft: 'auto',
|
|
|
- '&:hover': {
|
|
|
- outline: 'solid 3px #cccbcb',
|
|
|
- }
|
|
|
- },
|
|
|
- listItem_iconRightBtnHidden: {
|
|
|
- background: 'inherit',
|
|
|
- borderRadius: '50%',
|
|
|
- border: 'none',
|
|
|
- height: 24,
|
|
|
- width: 24,
|
|
|
- textAlign: 'center',
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- justifyContent: 'center',
|
|
|
- alignContent: 'center',
|
|
|
- fontSize: 12,
|
|
|
- marginLeft: 'auto',
|
|
|
- },
|
|
|
- listItem_icon_time: {
|
|
|
- fontSize: 12,
|
|
|
- marginLeft: 5,
|
|
|
- color: '#1b1b1b'
|
|
|
- },
|
|
|
- listItem_typing: {
|
|
|
- color: '#4d4d4d',
|
|
|
- animation: 'ripple 4s infinite ease-in-out',
|
|
|
- },
|
|
|
- listItem_dots: {
|
|
|
- color: '#1b1b1b',
|
|
|
- fontWeight: 'bold',
|
|
|
- display:'inline-block',
|
|
|
- fontFamily: 'monospace',
|
|
|
- clipPath: 'inset(0 3ch 0 0)',
|
|
|
- animation: `$run 2s steps(5) infinite`,
|
|
|
- },
|
|
|
- '@keyframes run': {
|
|
|
- to: {
|
|
|
- clipPath: 'inset(0 -1ch 0 0)'
|
|
|
- },
|
|
|
- },
|
|
|
})
|
|
|
|
|
|
const ChatsList = () => {
|
|
|
const classes = useStyles()
|
|
|
const dispatch = useDispatch()
|
|
|
const ref = useRef<any>(null)
|
|
|
- const [selectedIndex, setSelectedIndex] = useState<number>(1);
|
|
|
- const [modal, setModal] = useState<any>(false);
|
|
|
+ const [selectedIndex, setSelectedIndex] = useState<null | number>(null);
|
|
|
const { total, chats } = useSelector(getState)
|
|
|
const chat = useSelector(getChatMemo)
|
|
|
+ const isOpen = useSelector(getIsOpen)
|
|
|
|
|
|
const handleListItemClick = (i: number, companionId: string) => {
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
|
dispatch(actionScroll(false))
|
|
|
- dispatch(actionIsOpen(''))
|
|
|
+ isOpen&&dispatch(actionIsOpen(''))
|
|
|
setSelectedIndex(i);
|
|
|
}
|
|
|
|
|
@@ -198,12 +61,6 @@ const ChatsList = () => {
|
|
|
dispatch(actionScroll(true))
|
|
|
}
|
|
|
|
|
|
- const handleContextMenu = (e: any) => {
|
|
|
- e.preventDefault()
|
|
|
- const companionId = e.currentTarget.id
|
|
|
- const isChat = chats.find((el) => el.companionId === companionId)
|
|
|
- if (isChat) setModal(isChat)
|
|
|
- }
|
|
|
useEffect(() => {
|
|
|
dispatch(asyncGetChats())
|
|
|
const handleReset = () => dispatch(asyncGetChats())
|
|
@@ -216,9 +73,7 @@ const ChatsList = () => {
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
|
dispatch(actionScroll(true))
|
|
|
}
|
|
|
- if (chat.companionId&&!chats.find((el) => el.companionId === chat.companionId)) {
|
|
|
- dispatch(actionRemoveChat())
|
|
|
- }
|
|
|
+ if (chat.companionId&&!chats.find((el) => el.companionId === chat.companionId))dispatch(actionRemoveChat())
|
|
|
if (ref.current) {
|
|
|
ref.current.forEach(({total,seen}: any,i:number) => {
|
|
|
const oldDifferent = total - seen
|
|
@@ -236,47 +91,10 @@ const ChatsList = () => {
|
|
|
|
|
|
return total !== '0' ? (
|
|
|
<List className={classes.list} component="nav"
|
|
|
- aria-label="main mailbox folders">
|
|
|
- {chats.map(({ name, lastName, avatarUrl, color, companionId, mute, seen, total,
|
|
|
- watched, typing, number, online, lastMessage,lastMessageCreatedAt,createdAt }, i: number) =>
|
|
|
- <ListItemButton
|
|
|
- key={number}
|
|
|
- id={companionId}
|
|
|
- selected={selectedIndex === i}
|
|
|
- onClick={() => handleListItemClick(i, companionId)}
|
|
|
- onContextMenu={handleContextMenu}
|
|
|
- >
|
|
|
- {modal&&modal.companionId === companionId&&<ContextMenuBar setModal={setModal} mute={mute} companionId={companionId}/>}
|
|
|
- <ListItemIcon className={classes.listItem_iconAvatar}>
|
|
|
- <StyledBadge overlap="circular" variant={online === 'true'?'dot':'standard'}
|
|
|
- anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
|
|
|
- <Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
|
|
|
- sx={{ background: color, width: 54, height: 54 }}>
|
|
|
- {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
|
|
|
- </Avatar>
|
|
|
- </StyledBadge>
|
|
|
- </ListItemIcon>
|
|
|
- <ListItemText primary={<div className={classes.listItemInnerText}>
|
|
|
- <span>{`${firstLetter(name)}${slicedWord(name, 15, 1)}
|
|
|
- ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}</span>
|
|
|
- {mute&&<VolumeOffIcon className={classes.listItemInnerText__icon} fontSize='small' />}</div>}
|
|
|
- secondary={typing ? <span className={classes.listItem_typing}>
|
|
|
- typing<span className={classes.listItem_dots}>...</span></span> :
|
|
|
- lastMessage ? slicedWord(lastMessage, 35) :
|
|
|
- `${firstLetter(name)}${slicedWord(name, 8, 1)} joined Telegram`}/>
|
|
|
- <ListItemIcon className={classes.listItem_iconRight}>
|
|
|
- <div className={classes.listItem_iconTimeChecked}>
|
|
|
- {watched&& <DoneAllIcon style={{ color: '#18bd03' }} fontSize='small' />}
|
|
|
- <Typography className={classes.listItem_icon_time} variant="h6" color="initial">
|
|
|
- {timeStampEU(lastMessageCreatedAt?lastMessageCreatedAt:createdAt)}
|
|
|
- </Typography>
|
|
|
- </div>
|
|
|
- {lastMessage && 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>)}
|
|
|
- </List>
|
|
|
+ aria-label="main mailbox folders">
|
|
|
+ {chats.map((el, i: number) => <ChatItem key={el.number} chat={el} selectedIndex={selectedIndex} i={i}
|
|
|
+ handleListItemClick={handleListItemClick} handleNewMsgs={handleNewMsgs} setSelectedIndex={setSelectedIndex}/>)}
|
|
|
+ </List>
|
|
|
):<AlertInfo name='You do not have any chats yet!' />;
|
|
|
}
|
|
|
|