Skip to content

Commit 005ee76

Browse files
committed
Fix Download page re-rendering and preload builds from API
The `useSWR` API was being used incorrectly which broke preloading and would trigger the preloader animation to happen a lot more than necessary. In addition to that, we were also missing the opportunity to preload the builds JSON from the API.
1 parent 87f5abe commit 005ee76

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/pages/download.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import useSWR from "swr";
1313
import config from "../config";
1414

1515
const IndexPage = () => {
16-
const { data, isValidating } = useSWR("get-builds", async () => {
17-
const res = await axios.get(config.builds_api_url);
18-
console.log(res.status, res.data);
19-
return res.data;
20-
});
16+
const { data } = useSWR(
17+
config.builds_api_url,
18+
(url) => axios.get(url).then(r => r.data)
19+
);
2120

2221
return (
2322
<Layout title="Download Skyline - Nintendo Switch Emulator">
23+
<link rel="preload" href={config.builds_api_url} as="fetch" crossorigin="anonymous"/>
2424
<div className="w-full min-h-screen pb-0 md:pb-20 dark:bg-darkBackground">
2525
<div className="flex items-center justify-between">
2626
<div className="px-8 py-12 mx-auto md:py-18 max-w-page">
2727
<div className="pt-4 mx-auto text-center md:max-w-xl lg:max-w-3xl">
2828
<h3 className="mb-6 text-3xl font-bold text-black dark:text-white">Builds</h3>
2929
<p className="pb-2 mb-6 font-semibold text-blue-500 md:mb-12 md:pb-0">Click on Download to download the apk file for the emulator.</p>
3030
</div>
31-
{isValidating ? (
31+
{data === undefined ? (
3232
<Preloader />
3333
) : (
3434
data.map((build, idx) => {

0 commit comments

Comments
 (0)