forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created the banner structure and fixed the styling (reactplay#877)
* created the banner structure and fixed the styling * filtered the array and fixed the banner-button * fixed the linting issue * fixed the height of dynamic banner * fixed the backgroundImage issue * removed truncate class from description Co-authored-by: Tapas Adhikary <[email protected]>
- Loading branch information
1 parent
42b05ca
commit d6ea3d1
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Fragment, useEffect, useState } from 'react'; | ||
import thumbPlay from 'images/thumb-play.png'; | ||
import { Link } from 'react-router-dom'; | ||
import { MdArrowRightAlt } from 'react-icons/md'; | ||
|
||
const DynamicBanner = ({ randomPlay }) => { | ||
const [coverImage, setCoverImage] = useState(null); | ||
const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
if (loading && randomPlay && randomPlay.cover) { | ||
setCoverImage(randomPlay.cover); | ||
setLoading(false); | ||
} else { | ||
setLoading(true); | ||
import(`plays/${randomPlay.slug}/cover.png`) | ||
.then((Cover) => { | ||
setCoverImage(Cover.default); | ||
setLoading(false); | ||
}) | ||
.catch((err) => { | ||
setCoverImage(thumbPlay); | ||
|
||
return { | ||
success: false, | ||
error: err, | ||
message: `Cover image not found for the play ${randomPlay.name}. Setting the default cover image...` | ||
}; | ||
}); | ||
} | ||
}, [randomPlay]); | ||
|
||
if (loading) return <p>loading...</p>; | ||
|
||
return ( | ||
<Fragment> | ||
<div | ||
className="dynamic-banner-container" | ||
style={{ | ||
background: `linear-gradient(rgba(0,0,0,0.5), #020808),url(${coverImage} ) center/cover no-repeat`, | ||
minHeight: '50vh' | ||
}} | ||
> | ||
<div className="dynamic-banner-body md:pl-14 px-4 py-2 md:py-3"> | ||
<h1 className="text-white text-3xl md:text-4xl lg:text-5xl">{randomPlay.name}</h1> | ||
<p className="text-gray-400 mt-2 text-xs md:text-base ">{randomPlay.description}</p> | ||
<Link to={`/plays/${encodeURI(randomPlay?.github?.toLowerCase())}/${randomPlay.slug}`}> | ||
<button className="banner-button rounded-full font-extrabold uppercase px-8 md:px-12 md:py-1"> | ||
Let's Play <MdArrowRightAlt className="right-arrow-icon" size={40} /> | ||
</button> | ||
</Link> | ||
|
||
{/* <Link to={``}><button className='banner-button'>See Creator's profile</button></Link> */} | ||
</div> | ||
</div> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default DynamicBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters