index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import List from '@mui/material/List';
  2. import ListItemButton from '@mui/material/ListItemButton';
  3. import Avatar from '@mui/material/Avatar';
  4. import ListItemText from '@mui/material/ListItemText';
  5. import ListItemIcon from '@mui/material/ListItemIcon';
  6. import { makeStyles, Typography } from '@material-ui/core'
  7. import { useState } from 'react';
  8. import shortid from 'shortid';
  9. import doubleCheck from '../../../../img/clipart289625.png'
  10. import { chats } from './chats'
  11. const randomColor = () => "#" + Math.floor(Math.random() * 0xFFFFFF).toString(16);
  12. const useStyles = makeStyles({
  13. list: {
  14. width: '100%',
  15. maxHeight: '890px',
  16. overflowY: 'scroll',
  17. '&::-webkit-scrollbar': {
  18. width: '0.4em'
  19. },
  20. '&::-webkit-scrollbar-track': {
  21. boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  22. webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  23. backgroundColor: '#eceeec',
  24. },
  25. '&::-webkit-scrollbar-thumb': {
  26. backgroundColor: '#ccc8c8',
  27. },
  28. "&::-webkit-scrollbar-thumb:focus": {
  29. backgroundColor: "#959595",
  30. },
  31. "&::-webkit-scrollbar-thumb:active": {
  32. backgroundColor: "#959595",
  33. },
  34. },
  35. listItem: {},
  36. listItem_iconAvatar: {
  37. marginRight:10
  38. },
  39. listItem_iconRight: {
  40. marginRight: 10,
  41. display: 'flex',
  42. alignItems: 'center',
  43. justifyContent: 'center',
  44. alignContent: 'center',
  45. flexDirection: 'column'
  46. },
  47. listItem_iconTimeChecked: {
  48. display: 'flex',
  49. flexWrap: 'nowrap',
  50. alignItems: 'center',
  51. justifyContent: 'center',
  52. alignContent: 'center',
  53. marginBottom:2
  54. },
  55. listItem_iconRightBtn: {
  56. background: '#0ac40a',
  57. borderRadius: '50%',
  58. color: '#ffffff',
  59. border: 'none',
  60. height: 24,
  61. width: 24,
  62. textAlign: 'center',
  63. display: 'flex',
  64. alignItems: 'center',
  65. justifyContent: 'center',
  66. alignContent: 'center',
  67. fontSize: 12,
  68. marginLeft: 'auto',
  69. '&:hover': {
  70. outline: 'solid 3px #3ee415',
  71. }
  72. },
  73. listItem_icon_time: {
  74. fontSize: 12,
  75. marginLeft:5
  76. }
  77. })
  78. const ChatsList = () => {
  79. const [selectedIndex, setSelectedIndex] = useState<number>(1);
  80. const classes = useStyles()
  81. const handleListItemClick = (e: React.SyntheticEvent<Element, Event>, i: number) => {
  82. console.log(i,'index','selected chat in chat bar',e)
  83. setSelectedIndex(i);
  84. }
  85. const handleNewMsgS = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, i: number) => {
  86. e.stopPropagation()
  87. console.log(i,'index','clicked read new messages')
  88. }
  89. const data = new Date(2022, 3, 8).toLocaleString("en-US", {
  90. year:'numeric',
  91. month: 'short',
  92. day: 'numeric'
  93. });
  94. return (
  95. <List className={classes.list} component="nav"
  96. aria-label="main mailbox folders">
  97. {chats && chats.map((chat: any,i:number) =>
  98. <ListItemButton
  99. className={classes.listItem}
  100. key={shortid.generate()}
  101. selected={selectedIndex === i}
  102. onClick={(e) => handleListItemClick(e, i)}
  103. >
  104. <ListItemIcon className={classes.listItem_iconAvatar}>
  105. <Avatar alt={chat.name} src={chat.avatarUrl?chat.avatarUrl:undefined}
  106. sx={{ background: randomColor(), width: 54, height: 54 }}/>
  107. </ListItemIcon>
  108. <ListItemText primary={chat.name.slice(0,50)} secondary={chat.message.slice(0,35)} />
  109. <ListItemIcon className={classes.listItem_iconRight}>
  110. <div className={classes.listItem_iconTimeChecked}>
  111. <img alt='double check' width="16" height='16' src={doubleCheck} />
  112. <Typography className={classes.listItem_icon_time} variant="h6" color="initial">{data}</Typography>
  113. </div>
  114. <button onClick={(e) => handleNewMsgS(e,i)} className={classes.listItem_iconRightBtn}>17</button>
  115. </ListItemIcon>
  116. </ListItemButton>)}
  117. </List>
  118. );
  119. }
  120. export default ChatsList