Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ChatColumn.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React, { useState, useEffect } from "react";
  2. import ChatCard from "../Cards/ChatCard/ChatCard";
  3. import {
  4. ChatColumnContainer,
  5. HeaderBack,
  6. HeaderSelect,
  7. ListContainer,
  8. ListHeader,
  9. SelectOption,
  10. TitleSortContainer,
  11. } from "./ChatColumn.styled";
  12. import { sortEnum } from "../../enums/sortEnum";
  13. import useSorting from "../../hooks/useSorting";
  14. import { ReactComponent as Down } from "../../assets/images/svg/down-arrow.svg";
  15. import { IconStyled } from "../Icon/Icon.styled";
  16. import { Grid } from "@mui/material";
  17. import MailOutlineIcon from "@mui/icons-material/MailOutline";
  18. import { HeaderTitle } from "../ProfileCard/ProfileCard.styled";
  19. import { useTranslation } from "react-i18next";
  20. import { useDispatch, useSelector } from "react-redux";
  21. import { selectLatestChats } from "../../store/selectors/chatSelectors";
  22. import { fetchChats } from "../../store/actions/chat/chatActions";
  23. export const DownArrow = (props) => {
  24. <IconStyled {...props}>
  25. <Down />
  26. </IconStyled>;
  27. };
  28. export const ChatColumn = () => {
  29. const dispatch = useDispatch();
  30. const sorting = useSorting();
  31. const { t } = useTranslation();
  32. const [sortOption, setSortOption] = useState(sortEnum.INITIAL);
  33. const chats = useSelector(selectLatestChats);
  34. useEffect(() => {
  35. dispatch(fetchChats());
  36. }, []);
  37. useEffect(() => {
  38. setSortOption(sorting.selectedSortOption);
  39. }, [sorting.selectedSortOption]);
  40. const handleChangeSelect = (event) => {
  41. let chosenOption;
  42. for (const sortOption in sortEnum) {
  43. if (sortEnum[sortOption].value === event.target.value) {
  44. chosenOption = sortEnum[sortOption];
  45. sorting.changeSorting(chosenOption);
  46. }
  47. }
  48. };
  49. return (
  50. <ChatColumnContainer>
  51. <HeaderBack />
  52. <TitleSortContainer>
  53. <Grid
  54. container
  55. direction="row"
  56. justifyContent="start"
  57. alignItems="center"
  58. >
  59. <MailOutlineIcon color="action" sx={{ mr: 0.9 }} />
  60. <HeaderTitle>{t("header.myMessages")}</HeaderTitle>
  61. </Grid>
  62. <HeaderSelect
  63. value={sortOption?.value ? sortOption.value : sortEnum.INITIAL.value}
  64. IconComponent={DownArrow}
  65. onChange={handleChangeSelect}
  66. >
  67. {Object.keys(sortEnum).map((property) => {
  68. return (
  69. <SelectOption
  70. value={sortEnum[property].value}
  71. key={sortEnum[property].value}
  72. >
  73. {sortEnum[property].mainText}
  74. </SelectOption>
  75. );
  76. })}
  77. </HeaderSelect>
  78. </TitleSortContainer>
  79. <ListHeader enableSort={true} />
  80. <ListContainer>
  81. {chats.map((item, index) => (
  82. <ChatCard key={index} chat={item} />
  83. ))}
  84. </ListContainer>
  85. </ChatColumnContainer>
  86. );
  87. };
  88. export default ChatColumn;