-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Twitch info to client-side fetch of serverless api function
- Loading branch information
1 parent
6a7e636
commit f7a3978
Showing
12 changed files
with
220 additions
and
200 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
File renamed without changes.
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,38 @@ | ||
/** | ||
1. get data from api/twitch and then rewrite component ✅ | ||
2. use web worker | ||
3. we want to figure out how to gracefully load the thumbnail ... e.g. don't use a fallback but more of a skeleton loader effect | ||
*/ | ||
|
||
const wrapperEl = document.querySelector("[data-twitch-wrapper]"); | ||
const linkEl = document.querySelector("[data-twitch-link]"); | ||
const titleEl = document.querySelector("[data-twitch-title]"); | ||
const subtitleEl = document.querySelector("[data-twitch-subtitle]"); | ||
const thumbnailEl = document.querySelector("[data-twitch-thumbnail]"); | ||
|
||
async function getTwitchData() { | ||
const data = await fetch("/api/twitch").then((res) => res.json()); | ||
return data; | ||
} | ||
|
||
(async () => { | ||
const data = await getTwitchData(); | ||
|
||
if (data) { | ||
linkEl.href = data.link; | ||
titleEl.innerText = data.title; | ||
subtitleEl.innerText = data.subtitle; | ||
thumbnailEl.setAttribute("height", data.thumbnail.height); | ||
thumbnailEl.setAttribute("width", data.thumbnail.width); | ||
thumbnailEl.setAttribute("src", data.thumbnail.url); | ||
|
||
if (data.isLive) { | ||
thumbnailEl.setAttribute( | ||
"class", | ||
"twitchInfo__thumbnail twitchInfo__thumbnail--live", | ||
); | ||
wrapperEl.setAttribute("data-live", "true"); | ||
} | ||
} | ||
})(); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.