PostCard.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import defaultPhoto from '../../materials/default-photo.png'
  2. import { Link } from 'react-router-dom'
  3. import galery from '../../materials/gallery-icon.png'
  4. import backendURL from '../../helpers/backendUrl'
  5. import { videoRegex } from '../../helpers'
  6. const GalleryCard = ({ post = {} }) => (
  7. <div className="Wrapper">
  8. <img src={galery} className="Gallery" />
  9. <img className="Card" src={backendURL + '/' + post.images[0].url} />
  10. </div>
  11. )
  12. const ImageCard = ({ post = {} }) => (
  13. <div className="Wrapper">
  14. <img className="Card" src={backendURL + '/' + post.images[0].url} />
  15. </div>
  16. )
  17. const VideoCard = ({ post = {} }) => (
  18. <div className="Wrapper">
  19. <video className="Card">
  20. <source src={backendURL + '/' + post?.images[0]?.url} />
  21. </video>
  22. </div>
  23. )
  24. export const Card = ({ post }) => {
  25. return (
  26. <>
  27. <Link key={post?._id} to={`/post/${post?._id}`}>
  28. {post?.images && post?.images.length > 1 ? (
  29. post?.images &&
  30. post?.images[0] &&
  31. post?.images[0]?.originalFileName?.match(videoRegex) ? (
  32. <>
  33. <VideoCard post={post} />
  34. </>
  35. ) : (
  36. <GalleryCard post={post} />
  37. )
  38. ) : post?.images &&
  39. post?.images[0] &&
  40. post?.images[0]?.originalFileName?.match(videoRegex) ? (
  41. <VideoCard post={post} />
  42. ) : post?.images && post?.images[0] && post?.images[0]?.url ? (
  43. <ImageCard post={post} />
  44. ) : (
  45. <div className="Wrapper">
  46. <img className="Card" src={defaultPhoto} />
  47. </div>
  48. )}
  49. </Link>
  50. </>
  51. )
  52. }