-
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.
Updated frontend to always show newest Soundcloud track as iframe
- Loading branch information
Showing
4 changed files
with
111 additions
and
85 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import {Container} from "@mui/material"; | ||
|
||
function SoundCloudIFrame() { | ||
const iframeHtml = '<iframe title="Featured Track" ' + | ||
'width="100%" height="200" scrolling="no" frameborder="no" allow="autoplay" ' + | ||
'src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + | ||
'1892746719' + | ||
'&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true">' + | ||
'</iframe>' | ||
return ( | ||
<Container fixed style={{marginTop: '100px'}}> | ||
<div dangerouslySetInnerHTML={{__html: iframeHtml}}/> | ||
</Container> | ||
); | ||
function SoundCloudIFrame({newestContentId}) { | ||
if (newestContentId !== null && newestContentId !== undefined) { | ||
const iframeHtml = '<iframe title="Featured Track" ' + | ||
'width="100%" height="200" scrolling="no" frameborder="no" allow="autoplay" ' + | ||
'src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + | ||
newestContentId + | ||
'&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true">' + | ||
'</iframe>' | ||
|
||
return ( | ||
<Container fixed style={{marginTop: '100px'}}> | ||
<div dangerouslySetInnerHTML={{__html: iframeHtml}}/> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
export default SoundCloudIFrame; |
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,85 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
const useFetchNewsPostsAndNewestContent = () => { | ||
const [newsPosts, setNewsPosts] = useState(null); | ||
const [newestContentId, setNewestContentId] = useState(null); | ||
|
||
useEffect(() => { | ||
const query = ` | ||
{ | ||
newsPostCollection(order: [publicationDate_DESC, title_ASC], limit: 1000) { | ||
items { | ||
title | ||
shortTitle | ||
description | ||
originalUrl | ||
remoteId | ||
publicationDate | ||
isVideo | ||
isAudio | ||
thumbnailImage { | ||
contentType | ||
url | ||
} | ||
type { | ||
title | ||
channelDescription | ||
channelTitle | ||
channelUrl | ||
icon { | ||
contentType | ||
url | ||
} | ||
sys { | ||
id | ||
} | ||
} | ||
sys { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const fetchGraphQlData = (query, retries) => { | ||
window | ||
.fetch(`https://graphql.contentful.com/content/v1/spaces/wehngbocf979/`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer ck9CqB4ydwUdbKGF6quZzIqVS0JvmlMhWQJnFSnODrA", | ||
}, | ||
body: JSON.stringify({query}), | ||
}) | ||
.then((response) => response.json()) | ||
.then(({data, errors}) => { | ||
if (errors) { | ||
console.error(errors); | ||
console.log(`retries ${retries}, retrying? ${retries < 5}`); | ||
if (retries < 5) { | ||
setTimeout(() => { | ||
fetchGraphQlData(query, retries + 1); | ||
}, 1000) | ||
} | ||
} else { | ||
setNewsPosts(data.newsPostCollection.items); | ||
|
||
// Find the first SoundCloud post and set its remoteId as the newest content ID | ||
const soundCloudPost = data.newsPostCollection.items.find( | ||
item => item.type && item.type.title === "SoundCloud Track" | ||
); | ||
if (soundCloudPost) { | ||
setNewestContentId(soundCloudPost.remoteId); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
fetchGraphQlData(query, 0); | ||
}, []); | ||
|
||
return { newsPosts, newestContentId }; | ||
}; | ||
|
||
export default useFetchNewsPostsAndNewestContent; |