Skip to content

Commit

Permalink
KMtest URL
Browse files Browse the repository at this point in the history
  • Loading branch information
koustov committed Aug 14, 2022
1 parent 9006ba0 commit 3cc467b
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/common/playlists/PlayMeta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,53 @@ function PlayMeta() {
const [isError, setIsError] = useState(false);
let { playname, username } = useParams(); // return the parameter of url
const [metaImage, setMetaImage] = useState();
const [localImage, setLocalImage] = useState(thumbPlay);
const [ogTagImage, setOgTagImage] = useState();
// const [localImage, setLocalImage] = useState(thumbPlay);

/**
* Fetch local playImage
*/
const fetchLocalPlayCover = useCallback(async (playObj) => {
let metaImg = '';
let ogTagImg = '';
if(playObj.cover) {
metaImg = playObj.cover;
ogTagImg = playObj.cover;
setMetaImage(metaImg);
setOgTagImage(ogTagImg);
console.error(`Cover found: ${metaImage} > ${ogTagImage}`)
setLoading(false)
return
}
try {
/**
* Try to Fetch the local cover image
*/
const response = await import(`plays/${playObj.slug}/cover.png`);
setLocalImage(response.default);

metaImg = response.default;
ogTagImg = getLocalPlayCoverURL(response.default);
setMetaImage(metaImg);
setOgTagImage(ogTagImg);
console.error(`Local found: ${metaImage} > ${ogTagImage}`)
setLoading(false)
} catch (_error) {
/**
* On error set the default image
*/
setLocalImage(thumbPlay);

metaImg = thumbPlay;
ogTagImg = thumbPlay;
setMetaImage(metaImg);
setOgTagImage(ogTagImg);
console.error(`Local NOT found: ${metaImage} > ${ogTagImage}`)
setLoading(false)
}
}, []);

useEffect(() => {
console.log(`ENV: ${process.env.NEXT_PUBLIC_SITE_URL}`)
console.log(`ENV: ${process.env.VERCEL_URL}`)
submit(FetchPlaysBySlugAndUser(decodeURI(playname), decodeURI(username)))
.then((res) => {
const play_obj = res[0];
Expand Down Expand Up @@ -77,7 +103,7 @@ function PlayMeta() {
<meta property="og:description" content={play.description} />
<meta
property="og:image"
content={metaImage ? metaImage : localImage}
content={metaImage}
data-react-helmet="true"
/>
<meta
Expand All @@ -97,7 +123,7 @@ function PlayMeta() {
/>
<meta
name="twitter:image"
content={metaImage ? metaImage : getLocalPlayCoverURL(localImage)}
content={ogTagImage}
data-react-helmet="true"
/>
</Helmet>
Expand Down

0 comments on commit 3cc467b

Please sign in to comment.