Skip to content

Commit

Permalink
Merge pull request #16 from LarveyOfficial/dev
Browse files Browse the repository at this point in the history
No need for errors if we keep the old data anyways.
  • Loading branch information
LarveyOfficial authored Apr 8, 2024
2 parents 832e70e + a0b6c3b commit 6a9c134
Showing 1 changed file with 1 addition and 49 deletions.
50 changes: 1 addition & 49 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,17 @@ import { Analytics } from "@vercel/analytics/react";
import Head from "next/head";
import { useRouter } from "next/router";
import { useKeyboardShortcut } from "../hooks/useKeyboardShortcut";
import { useState } from "react";

const fetcher = (url: RequestInfo | URL) =>
fetch(url).then((res) => res.json());

export default function Gif() {
const router = useRouter();

const [isRealError, setIsRealError] = useState(false);

// Check for new image every 1 second
const { data, error } = useSWR("/api/getConfig", fetcher, {
const { data } = useSWR("/api/getConfig", fetcher, {
refreshInterval: 1000,
keepPreviousData: true,
shouldRetryOnError: true,
onErrorRetry: (error, key, config, revalidate, { retryCount }) => {
if (retryCount < 10) {
setIsRealError(false);
} else {
setIsRealError(true);
}
// Retry every second
setTimeout(() => revalidate({ retryCount }), 5000);
},
});

// Take user to panel when keybind detected
Expand All @@ -37,41 +24,6 @@ export default function Gif() {

useKeyboardShortcut(["ctrl", "p"], goToPanel);

// If data grab fails, show sad face
if (error && isRealError)
return (
<section className="flex h-full items-center dark:bg-gray-800 dark:text-gray-100 sm:p-16">
<div className="container mx-auto my-8 flex flex-col items-center justify-center space-y-8 px-5 text-center sm:max-w-md">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
className="h-40 w-40 dark:text-gray-600"
>
<path
fill="currentColor"
d="M256,16C123.452,16,16,123.452,16,256S123.452,496,256,496,496,388.548,496,256,388.548,16,256,16ZM403.078,403.078a207.253,207.253,0,1,1,44.589-66.125A207.332,207.332,0,0,1,403.078,403.078Z"
></path>
<rect
width="176"
height="32"
x="168"
y="320"
fill="currentColor"
></rect>
<polygon
fill="currentColor"
points="210.63 228.042 186.588 206.671 207.958 182.63 184.042 161.37 162.671 185.412 138.63 164.042 117.37 187.958 141.412 209.329 120.042 233.37 143.958 254.63 165.329 230.588 189.37 251.958 210.63 228.042"
></polygon>
<polygon
fill="currentColor"
points="383.958 182.63 360.042 161.37 338.671 185.412 314.63 164.042 293.37 187.958 317.412 209.329 296.042 233.37 319.958 254.63 341.329 230.588 365.37 251.958 386.63 228.042 362.588 206.671 383.958 182.63"
></polygon>
</svg>
<p className="text-3xl">Something went wrong. Try again later</p>
</div>
</section>
);

// While data is loading, show loading animation
if (!data)
return (
Expand Down

0 comments on commit 6a9c134

Please sign in to comment.