import { m } from "framer-motion";
import { ReactElement, useEffect, useState } from "react";
import HomeLayout from "../layouts/HomeLayout";
import { homeMain } from "../layouts/NavTemplates";
import Image from "next/image";
function Home() {
const [emotesUrls, setEmotes] = useState([]);
const [currentEmote, setCurrentEmote] = useState(0);
useEffect(() => {
fetch("/api/emotes")
.then((res) => res.json())
.then((data) => {
// if error, return
if (data.error) {
return;
}
// get all emote URLs
let emoteUrls = data["7tv"].channel.map((emote: any) => {
let base_url = emote.data.host.url;
// get the largest emote size, append it to the base url
let largest = emote.data.host.files[emote.data.host.files.length - 1];
// if width != height, skip it
if (largest.width !== largest.height) {
return null;
}
return `https:${base_url}/${largest.name}`;
});
// remove null values
emoteUrls = emoteUrls.filter((emote: any) => emote !== null);
setEmotes(emoteUrls);
setCurrentEmote(Math.floor(Math.random() * emoteUrls.length));
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// change emote every 5 seconds, separated from the fetch call so it only initializes once when the emotes are loaded
useEffect(() => {
const interval = setInterval(() => {
// choose a random emote
let randomEmote = Math.floor(Math.random() * emotesUrls.length);
setCurrentEmote(randomEmote);
}, 5000);
return () => clearInterval(interval);
}, [emotesUrls]);
// until the emotes are loaded, show the logo as a placeholder
let slideShow = (