Avatar.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React, {useEffect} from "react";
  2. import { connect } from "react-redux";
  3. import { backURL } from "../constants";
  4. function getUrl(obj) {
  5. if (obj.avatar?.url) {
  6. return backURL + obj.avatar?.url;
  7. } else {
  8. return false;
  9. }
  10. }
  11. export const UserAvatar = ({ profile, text = "", className = "small" }) => {
  12. useEffect(() => {}, [getUrl(profile)])
  13. return (
  14. <>
  15. {console.log(getUrl(profile), "gjfsghfklsglk")}
  16. <div style={{display: "flex", alignItems: 'center'}}>
  17. <img className={className} src={getUrl(profile)} />
  18. <p>{text}</p>
  19. </div>
  20. </>
  21. );
  22. };
  23. export const CMyAvatar = connect((state) => ({
  24. profile: state.promise.myProfile?.payload || {},
  25. }))(UserAvatar);
  26. export const ChatAvatar = ({ userChat, text = "", className = "small", _id }) => {
  27. return (
  28. <>
  29. <div style={{display: "flex", alignItems: 'center'}}>
  30. {userChat[_id]?.avatar?.url ? <img className={className} src={backURL + userChat[_id]?.avatar?.url} /> : <div className="avatarStubChat"></div>}
  31. <p>{text}</p>
  32. </div>
  33. </>
  34. )
  35. }
  36. export const CChatAvatar = connect((state) => ({
  37. userChat: state.chats || {},
  38. }))(ChatAvatar);
  39. const SearchAvatar = ({findUser, avatarUrl}) => {
  40. return(
  41. <div className="searchBlock">
  42. <img src={backURL + avatarUrl?.avatar?.url} className="smallForChat"/>
  43. </div>
  44. )
  45. }
  46. export const CSearchAvatar = connect((state) => ({findUser: state?.promise?.findUser?.payload}))(
  47. SearchAvatar
  48. )