InvestWeb/pages/index.tsx

204 lines
5 KiB
TypeScript
Raw Normal View History

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";
2023-01-16 22:34:11 -05:00
function Home() {
const [emotesUrls, setEmotes] = useState([]);
const [currentEmote, setCurrentEmote] = useState(0);
2022-12-10 05:54:00 -05:00
useEffect(() => {
2023-01-23 03:36:04 -05:00
fetch("/api/emotes")
.then((res) => res.json())
.then((data) => {
2023-01-19 22:17:49 -05:00
// if error, return
if (data.error) {
return;
}
// get all emote URLs
2023-01-23 03:36:04 -05:00
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;
}
2023-01-23 03:36:04 -05:00
return `https:${base_url}/${largest.name}`;
});
// remove null values
emoteUrls = emoteUrls.filter((emote: any) => emote !== null);
setEmotes(emoteUrls);
2022-12-08 21:40:02 -05:00
setCurrentEmote(Math.floor(Math.random() * emoteUrls.length));
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
2022-12-10 05:54:00 -05:00
// 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 = (
<Image
src="/img/logo.webp"
2022-12-31 05:22:27 -05:00
alt="toffee Logo"
width={128}
height={128}
className="ml-4 mr-6"
/>
);
2022-12-12 04:19:17 -05:00
// if the emotes are loaded, show the slideshow
if (emotesUrls.length > 0) {
slideShow = (
<Image
src={emotesUrls[currentEmote]}
alt="7tv emote"
width={128}
height={128}
className="ml-4 mr-6"
/>
);
}
2022-11-23 17:20:36 -05:00
return (
2022-12-10 05:54:00 -05:00
<>
<div className="flex h-full w-full flex-col items-center justify-center">
2023-01-16 22:39:51 -05:00
<div className="inline-grid grid-cols-1 gap-20 text-white md:grid-cols-3">
2022-12-08 21:40:02 -05:00
<m.div
2023-01-16 22:34:11 -05:00
className="flex flex-col from-purple-400 to-pink-600 font-plusJakarta md:col-span-2"
2022-12-13 03:15:00 -05:00
variants={sloganContainerVariants}
initial="initial"
animate="animate"
2022-12-08 21:40:02 -05:00
>
2023-01-16 22:34:11 -05:00
<div className="flex flex-row text-8xl font-bold italic">
<m.h1 variants={sloganHeaderVariants}>t</m.h1>
<m.h1 className="text-orange-400" variants={sloganHeaderVariants}>
2022-12-31 05:22:27 -05:00
off
2023-01-16 22:34:11 -05:00
</m.h1>
<m.h1 variants={sloganHeaderVariants}>ee</m.h1>
</div>
<div className="text-xl italic">
<m.h2 variants={sloganHeaderVariants}>
a tax-free offline emote exchange utility
</m.h2>
</div>
2022-12-08 21:40:02 -05:00
</m.div>
2022-12-10 05:54:00 -05:00
<m.div
className="flex items-center justify-center"
2022-12-13 03:15:00 -05:00
variants={slideShowVariants}
initial="initial"
animate="animate"
2022-12-08 21:40:02 -05:00
>
2022-12-10 05:54:00 -05:00
{slideShow}
2022-12-31 05:22:27 -05:00
<m.div
className="fixed"
variants={sloganSecondaryContainerVariants}
>
<m.h2
className="font-minecraft text-sm font-normal text-yellow-300 drop-shadow-[0_2px_2px_rgba(0,0,0,0.99)]"
variants={sloganSecondaryVariants}
>
currently in development!
</m.h2>
</m.div>
2022-12-10 05:54:00 -05:00
</m.div>
</div>
</div>
2022-12-10 05:54:00 -05:00
</>
2022-11-23 17:20:36 -05:00
);
2023-01-16 22:34:11 -05:00
}
2022-12-13 03:15:00 -05:00
const sloganContainerVariants = {
initial: {
opacity: 0,
y: -100,
},
animate: {
opacity: 1,
y: 0,
transition: {
delay: 0.5,
duration: 2.5,
type: "spring",
bounce: 0.5,
stiffness: 150,
2022-12-31 05:22:27 -05:00
delayChildren: 1.0,
2023-01-16 22:34:11 -05:00
staggerChildren: 0.1,
2022-12-13 03:15:00 -05:00
},
},
};
const sloganHeaderVariants = {
initial: {
opacity: 0,
2023-01-16 22:34:11 -05:00
y: -15,
2022-12-13 03:15:00 -05:00
},
animate: {
opacity: 1,
2023-01-16 22:34:11 -05:00
y: 0,
2022-12-13 03:15:00 -05:00
},
};
2022-12-31 05:22:27 -05:00
const sloganSecondaryContainerVariants = {
2022-12-13 03:15:00 -05:00
initial: {
opacity: 0,
2022-12-31 05:22:27 -05:00
rotate: 0,
2022-12-13 03:15:00 -05:00
},
animate: {
opacity: 1,
2022-12-31 05:22:27 -05:00
rotate: -15,
2022-12-13 03:15:00 -05:00
transition: {
delay: 3.5,
2022-12-31 05:22:27 -05:00
duration: 1.0,
},
},
};
const sloganSecondaryVariants = {
animate: {
fontSize: ["1.5rem", "1.575rem", "1.5rem"],
transition: {
duration: 0.5,
repeat: Infinity,
2022-12-13 03:15:00 -05:00
},
},
};
const slideShowVariants = {
initial: {
opacity: 0,
},
animate: {
opacity: 1,
transition: {
delay: 2.0,
duration: 1.0,
},
},
};
// set the layout for the page, this is used to wrap the page in a layout
Home.getLayout = function getLayout(page: ReactElement) {
2023-01-26 05:20:07 -05:00
const metaTags = {
title: "Home - toffee",
};
return (
<HomeLayout navOptions={homeMain} metaTags={metaTags}>
{page}
</HomeLayout>
);
};
export default Home;