|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import { Link } from 'react-router-dom'; |
3 | 3 | import { BsPlayCircleFill } from 'react-icons/bs'; |
4 | 4 | import { BiLogoTypescript, BiLogoJavascript } from 'react-icons/bi'; |
5 | 5 | import PlayShare from './PlayShare.jsx'; |
6 | | - |
7 | | -import Shimmer from 'react-shimmer-effect'; |
8 | 6 | import Like from 'common/components/Like/Like'; |
9 | 7 | import userImage from 'images/user.png'; |
10 | 8 |
|
| 9 | +const formatDate = (dateString) => dateString || ''; |
| 10 | + |
11 | 11 | function PlayCard({ play, cover, likeObject }) { |
12 | | - return ( |
13 | | - <Link to={`/plays/${encodeURI(play.github.toLowerCase())}/${play.slug}`}> |
14 | | - <div className="play-card-container"> |
15 | | - <div className="play-thumb-container"> |
16 | | - <Shimmer> |
17 | | - <img alt="" className="play-card-thumb-img" src={cover} /> |
18 | | - </Shimmer> |
19 | | - <BsPlayCircleFill className="play-icon" color="white" size={80} /> |
| 12 | + const [isExpanded, setIsExpanded] = useState(false); |
| 13 | + if (!play || !play.github || !play.slug) return null; |
| 14 | + |
| 15 | + const avatarSrc = |
| 16 | + play?.user?.avatarUrl && play.user.avatarUrl.length ? play.user.avatarUrl : userImage; |
| 17 | + |
| 18 | + const LanguageBadge = () => { |
| 19 | + if (play.language === 'ts') { |
| 20 | + return ( |
| 21 | + <div className="flex items-start space-x-1 bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded-md w-fit mb-3"> |
| 22 | + <BiLogoTypescript color="#007acc" size={16} /> |
| 23 | + <span>Typescript</span> |
20 | 24 | </div> |
| 25 | + ); |
| 26 | + } |
| 27 | + if (play.language === 'js') { |
| 28 | + return ( |
| 29 | + <div className="flex items-start space-x-1 bg-yellow-100 text-yellow-800 text-xs font-semibold px-2.5 py-0.5 rounded-md w-fit mb-3"> |
| 30 | + <BiLogoJavascript color="#F0DB4F" size={16} /> |
| 31 | + <span>Javascript</span> |
| 32 | + </div> |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + return null; |
| 37 | + }; |
| 38 | + |
| 39 | + const linkTo = `/plays/${encodeURI(play.github.toLowerCase())}/${play.slug}`; |
21 | 40 |
|
22 | | - {/* <div className="border" /> */} |
23 | | - <div className="card-header">{play.name}</div> |
24 | | - {play.user && ( |
25 | | - <div className="author"> |
26 | | - <img |
27 | | - alt="avatar" |
28 | | - className="rounded-full border border-zink" |
29 | | - height="25px" |
30 | | - loading="lazy" |
31 | | - src={ |
32 | | - play?.user.avatarUrl |
33 | | - ? play?.user.avatarUrl.length |
34 | | - ? play?.user.avatarUrl |
35 | | - : userImage |
36 | | - : userImage |
37 | | - } |
38 | | - width="25px" |
| 41 | + return ( |
| 42 | + <Link className="group block" to={linkTo}> |
| 43 | + <div className="play-card-container max-w-sm bg-white rounded-xl overflow-hidden flex flex-col h-full"> |
| 44 | + {cover && ( |
| 45 | + <div className="relative h-48"> |
| 46 | + <img alt={play.name} className="w-full h-full object-cover" src={cover} /> |
| 47 | + <div className="absolute inset-0 thumb-overlay pointer-events-none" /> |
| 48 | + <BsPlayCircleFill |
| 49 | + className="absolute inset-0 m-auto z-10 opacity-0 transition-opacity duration-200 pointer-events-none" |
| 50 | + color="white" |
| 51 | + size={80} |
39 | 52 | /> |
40 | | - <div className="author-name">{play?.user.displayName}</div> |
41 | 53 | </div> |
42 | 54 | )} |
43 | | - <div className="play-actions mt-4"> |
44 | | - <div className="like-container"> |
45 | | - <Like likeObj={likeObject()} onLikeClick={null} /> |
46 | | - <div style={{ display: 'flex', alignItems: 'center' }}> |
47 | | - <PlayShare |
48 | | - cover={cover} |
49 | | - link={`/plays/${encodeURI(play.github.toLowerCase())}/${play.slug}`} |
| 55 | + |
| 56 | + <div className="p-5 flex flex-col flex-grow"> |
| 57 | + <LanguageBadge /> |
| 58 | + |
| 59 | + {play.user?.displayName && ( |
| 60 | + <div className="flex items-center text-sm text-gray-600 mb-4"> |
| 61 | + <img |
| 62 | + alt="avatar" |
| 63 | + className="rounded-full h-6 w-6 object-cover mr-2" |
| 64 | + loading="lazy" |
| 65 | + src={avatarSrc} |
50 | 66 | /> |
51 | | - {play.language === 'ts' ? ( |
52 | | - <BiLogoTypescript className="lang-icon" color="#007acc" size={25} /> |
53 | | - ) : ( |
54 | | - <BiLogoJavascript className="lang-icon" color="#F0DB4F" size={25} /> |
| 67 | + <span className="font-semibold text-gray-800">{play.user.displayName}</span> |
| 68 | + {play.date && ( |
| 69 | + <> |
| 70 | + <span className="mx-2">—</span> |
| 71 | + <span className="text-gray-500">{formatDate(play.date)}</span> |
| 72 | + </> |
55 | 73 | )} |
56 | 74 | </div> |
| 75 | + )} |
| 76 | + |
| 77 | + <div className="card-header text-md font-bold text-gray-900 mb-2">{play.name}</div> |
| 78 | + |
| 79 | + {play.description && ( |
| 80 | + <div className="mb-6 flex-grow"> |
| 81 | + <p className={`text-gray-700 text-xs ${!isExpanded ? 'line-clamp-3' : ''}`}> |
| 82 | + {play.description} |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + )} |
| 86 | + |
| 87 | + <div className="mt-auto flex items-center justify-between pt-4 border-t border-gray-100"> |
| 88 | + {likeObject && |
| 89 | + (() => { |
| 90 | + const data = likeObject?.(); |
| 91 | + |
| 92 | + return ( |
| 93 | + <div className="inline-flex items-center gap-2 whitespace-nowrap"> |
| 94 | + <Like likeObj={data} onLikeClick={null} /> |
| 95 | + </div> |
| 96 | + ); |
| 97 | + })()} |
| 98 | + |
| 99 | + <div className="flex items-center gap-3"> |
| 100 | + <div className="flex items-center gap-3" onClick={(e) => e.preventDefault()}> |
| 101 | + <PlayShare cover={cover} link={linkTo} /> |
| 102 | + </div> |
| 103 | + </div> |
57 | 104 | </div> |
58 | 105 | </div> |
59 | 106 | </div> |
| 107 | + |
| 108 | + <style> |
| 109 | + {` |
| 110 | + .group:hover .play-card-container .relative .z-10 { opacity: 1; } |
| 111 | +
|
| 112 | + .group:hover .play-card-container .relative .thumb-overlay { |
| 113 | + background-color: rgba(0, 0, 0, 0.4); |
| 114 | + backdrop-filter: blur(6px); |
| 115 | + -webkit-backdrop-filter: blur(6px); |
| 116 | + transition: background-color 200ms ease, backdrop-filter 200ms ease; |
| 117 | + } |
| 118 | + `} |
| 119 | + </style> |
60 | 120 | </Link> |
61 | 121 | ); |
62 | 122 | } |
|
0 commit comments