Merge pull request #211 from arch0Xd/master

szerveroldaliba
This commit is contained in:
skidoodle 2022-08-30 17:09:55 +02:00 committed by GitHub
commit f001036830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,6 @@
import Image from "next/image";
import Link from "next/link";
import React from "react";
import useSWR from "swr";
import React, { useEffect } from "react";
import FadeIn from "react-fade-in";
import { socials } from "components/data/socials";
@ -10,14 +9,14 @@ import { Toaster } from "react-hot-toast";
import { FaSpotify } from "react-icons/fa";
import profilePic from "../public/profile.webp";
import { GetServerSideProps } from "next";
import { useRouter } from "next/router";
const fetcher = (url: RequestInfo) => fetch(url).then((r) => r.json());
export default function ({ spotify }: any) {
const { asPath, replace } = useRouter()
useEffect(() => { replace(asPath) }, [spotify])
export default function () {
const { data: spotify } = useSWR("/api/spotify", fetcher, {
refreshInterval: 1000,
});
if (!spotify) return;
return (
<FadeIn>
<div className="px-8 w-11/12 m-auto rounded-lg max-w-4xl">
@ -79,3 +78,14 @@ export default function () {
</FadeIn>
);
}
export const getServerSideProps: GetServerSideProps = async () => {
const { HOST } = process.env
const res = await fetch(`${HOST}/api/spotify`)
const data = await res.json()
return {
props: { spotify: data }
}
}