|
@@ -1,14 +1,17 @@
|
|
|
import { makeStyles } from '@material-ui/core'
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import React, { useState } from 'react'
|
|
|
-import MenuList from '@mui/material/MenuList';
|
|
|
-import Avatar from '@mui/material/Avatar';
|
|
|
-import MenuItem from '@mui/material/MenuItem';
|
|
|
+import List from '@mui/material/List';
|
|
|
+import ListItem from '@mui/material/ListItem';
|
|
|
+import Divider from '@mui/material/Divider';
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
|
|
+import ListItemAvatar from '@mui/material/ListItemAvatar';
|
|
|
+import Avatar from '@mui/material/Avatar';
|
|
|
+import Typography from '@mui/material/Typography';
|
|
|
import Search from './Search'
|
|
|
import AlertInfo from "../../../../../reusableComponents/AlertInfo";
|
|
|
import { getMessages } from '../../../../../../redux/messages/selector'
|
|
|
-import { format,timeStamp,firstLetter,slicedWord } from '../../../../../../helpers'
|
|
|
+import { timeStamp,timeStampFilter,firstLetter,slicedWord } from '../../../../../../helpers'
|
|
|
import shortid from 'shortid';
|
|
|
|
|
|
|
|
@@ -25,16 +28,10 @@ const useStyles = makeStyles({
|
|
|
backgroundColor: '#ffffff'
|
|
|
},
|
|
|
listItem: {
|
|
|
- marginBottom: 5,
|
|
|
- paddingBottom: 5,
|
|
|
- borderBottom: 'solid 1px #ececec',
|
|
|
- },
|
|
|
- message: {
|
|
|
- width: '100%',
|
|
|
- wordBreak: 'break-word',
|
|
|
- textAlign: "left",
|
|
|
- padding:'0 10px',
|
|
|
- color:'#363636'
|
|
|
+ borderBottom: 'solid 1px #e6e6e6',
|
|
|
+ '&:hover': {
|
|
|
+ backgroundColor: '#e6e6e6',
|
|
|
+ }
|
|
|
},
|
|
|
})
|
|
|
|
|
@@ -42,30 +39,54 @@ const SearchList= () => {
|
|
|
const classes = useStyles()
|
|
|
const messages = useSelector(getMessages)
|
|
|
const [value, setValue] = useState<string>('')
|
|
|
- const handleSearch = (e: React.ChangeEvent<HTMLInputElement>): void => setValue(format(e.target.value))
|
|
|
- const filteredMessages = () => messages.filter((el) =>
|
|
|
- el.message.toLowerCase().includes(value.toLowerCase()))
|
|
|
+ const [date, setDate] = useState<any>('');
|
|
|
+ const handleSearch = (e: React.ChangeEvent<HTMLInputElement>): void => setValue(e.target.value)
|
|
|
|
|
|
+ const filteredMessages = () => messages.filter((el) => {
|
|
|
+ if (!date) {
|
|
|
+ return el.message.toLowerCase().includes(value.toLowerCase())
|
|
|
+ } else if (el.message.toLowerCase().includes(value.toLowerCase())
|
|
|
+ && timeStampFilter(date) === timeStampFilter(el.createdAt)) {
|
|
|
+ return el
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const arr = filteredMessages()
|
|
|
return (
|
|
|
<div>
|
|
|
- <Search handleSearch={handleSearch}/>
|
|
|
+ <Search handleSearch={handleSearch} value={value}
|
|
|
+ setDate={setDate} date={date} />
|
|
|
<div className={classes.containerAbsolute}>
|
|
|
- {messages.length > 0 ?
|
|
|
- <MenuList >
|
|
|
- {filteredMessages().map(({ name, lastName, avatarUrl, color, message, createdAt }) =>
|
|
|
- <div className={classes.listItem}>
|
|
|
- <MenuItem style={{marginBottom:5}} key={shortid.generate()} onClick={() => console.log('clicked message in rightList')}>
|
|
|
- <Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
|
|
|
- sx={{ background: color, width: 44, height: 44, marginRight:2 }}>
|
|
|
- {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
|
|
|
- </Avatar>
|
|
|
- <ListItemText primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
|
|
|
- ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`} secondary={timeStamp(createdAt)} />
|
|
|
- </MenuItem>
|
|
|
- <div className={classes.message}>{message}</div>
|
|
|
- </div> )}
|
|
|
- </MenuList> :
|
|
|
- <AlertInfo name='You do not have messages yet!' />}
|
|
|
+ {messages.length > 0 ? arr.length > 0 ?
|
|
|
+ <List sx={{ width: '100%' }}>
|
|
|
+ {arr.map(({ name, lastName, avatarUrl, color, message, createdAt }) =>
|
|
|
+ <ListItem alignItems="flex-start" className={classes.listItem} key={shortid.generate()}
|
|
|
+ onClick={() => console.log('clicked message in rightList')}>
|
|
|
+ <ListItemAvatar>
|
|
|
+ <Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
|
|
|
+ sx={{ background: color, width: 44, height: 44, marginRight:2 }}>
|
|
|
+ {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
|
|
|
+ </Avatar>
|
|
|
+ </ListItemAvatar>
|
|
|
+ <ListItemText
|
|
|
+ primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
|
|
|
+ ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
|
|
|
+ secondary={<>
|
|
|
+ <Typography
|
|
|
+ sx={{ display: 'block',wordBreak:'break-word' }}
|
|
|
+ component="span"
|
|
|
+ variant="body2"
|
|
|
+ color="text.primary"
|
|
|
+ >
|
|
|
+ {message}
|
|
|
+ </Typography>
|
|
|
+ {timeStamp(createdAt)}
|
|
|
+ </>}
|
|
|
+ />
|
|
|
+ </ListItem>)}
|
|
|
+ </List> :
|
|
|
+ <AlertInfo name={!date&&value ? `Messages not found with Search by request: ${value}`:
|
|
|
+ `Messages not found with Search by DataPicker: ${timeStampFilter(date)} and request: ${value}`} />:
|
|
|
+ <AlertInfo name='You do not have messages yet!' />}
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|