Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ChatCard.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. import {
  4. ChatInfo,
  5. ChatCardContainer,
  6. Col,
  7. UserImage,
  8. UserImgWrapper,
  9. UserName,
  10. LastMessage,
  11. Line,
  12. } from "./ChatCard.styled";
  13. import { useHistory } from "react-router-dom";
  14. import useScreenDimensions from "../../../hooks/useScreenDimensions";
  15. import LittleOfferDetails from "./LittleOfferDetails/LittleOfferDetails";
  16. import MobileOfferDetails from "./MobileOfferDetails/MobileOfferDetails";
  17. import OfferLocation from "./OfferLocation/OfferLocation";
  18. import ChatCommands from "./ChatCommands/ChatCommands";
  19. const ChatCard = (props) => {
  20. const history = useHistory();
  21. const dimensions = useScreenDimensions();
  22. const chat = useMemo(() => {
  23. return props.chat;
  24. }, [props.chat]);
  25. const lastMessage = useMemo(() => {
  26. if (chat?.chat?.messages && chat?.chat?.messages?.length > 0) {
  27. return chat.chat.messages[chat.chat.messages.length - 1]?.text;
  28. }
  29. return "";
  30. }, [chat]);
  31. const routeToItem = () => {
  32. history.push(`/messages/${chat?.chat?._id}`);
  33. };
  34. return (
  35. <ChatCardContainer
  36. onClick={
  37. dimensions.width < 600 ? () => routeToItem(chat?.chat?._id) : () => {}
  38. }
  39. >
  40. <Col>
  41. <UserImgWrapper>
  42. <UserImage src={chat?.interlocutorData?.image} />
  43. </UserImgWrapper>
  44. <ChatInfo>
  45. <UserName>{chat?.interlocutorData?.name}</UserName>
  46. {/* Only shows on Mobile */}
  47. <MobileOfferDetails chat={chat} />
  48. {/* ^^^^^ */}
  49. <LastMessage>{lastMessage}</LastMessage>
  50. <OfferLocation chat={chat} />
  51. </ChatInfo>
  52. </Col>
  53. <Line />
  54. {/* Only shows on Desktop */}
  55. <LittleOfferDetails chat={chat} />
  56. {/* ^^^^^^^ */}
  57. <ChatCommands routeToItem={() => routeToItem(chat?.chat?._id)} />
  58. </ChatCardContainer>
  59. );
  60. };
  61. ChatCard.propTypes = {
  62. children: PropTypes.node,
  63. title: PropTypes.string,
  64. description: PropTypes.string,
  65. category: PropTypes.string,
  66. author: PropTypes.string,
  67. location: PropTypes.string,
  68. image: PropTypes.node,
  69. quantity: PropTypes.number,
  70. package: PropTypes.string,
  71. numberOfViews: PropTypes.number,
  72. halfwidth: PropTypes.bool,
  73. sponsored: PropTypes.bool,
  74. offer: PropTypes.any,
  75. pinned: PropTypes.bool,
  76. vertical: PropTypes.bool,
  77. chat: PropTypes.any,
  78. };
  79. ChatCard.defaultProps = {
  80. halfwidth: false,
  81. sponsored: false,
  82. };
  83. export default ChatCard;