diff --git a/src/components/Sponsors/Sponsors.tsx b/src/components/Sponsors/Sponsors.tsx index dc8c53e491..d53ef02b20 100644 --- a/src/components/Sponsors/Sponsors.tsx +++ b/src/components/Sponsors/Sponsors.tsx @@ -1,23 +1,65 @@ import React, { useState, useEffect } from 'react'; import { useColorMode } from '@docusaurus/theme-common'; import { sanitize } from 'dompurify'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faSpinner } from '@fortawesome/free-solid-svg-icons'; + +const cycleIntervalMs = 30000; // 10 seconds export default function Sponsors(): React.JSX.Element { - const [data, setData] = useState(null); + const [loading, setLoading] = useState(true); + const [data, setData] = useState(null); + const [counter, setCounter] = useState(0); + const [seconds, setSeconds] = useState(0); const { colorMode } = useColorMode(); + const countUp = (stateFunc: React.Dispatch>, intervalMs: number): (() => void) => { + const interval = setInterval(() => { + stateFunc((x) => x + 1); + }, intervalMs); + + return () => clearInterval(interval); + }; + + useEffect(() => { + return countUp(setCounter, cycleIntervalMs); + }, []); + + useEffect(() => { + return countUp(setSeconds, cycleIntervalMs / 5); + }, []); + async function fetchData(mode: string, page: string): Promise { const response = await fetch(`https://build.betaflight.com/api/configurator/sponsors/${mode}/${page}`); - setData(await response.text()); + setLoading(true); + setTimeout(async () => { + setData(await response.text()); + setLoading(false); + }, 1000); } useEffect(() => { fetchData(colorMode, 'landing'); - }, [colorMode]); - - if (!data) { - return
Loading...
; - } + }, [colorMode, counter]); - return
; + return ( +
+ {data ? ( +
+ ) : ( +
+ + Loading... +
+ )} +
+ {[...Array((seconds % 5) + 1)].map((_, i) => ( +
+ ))} + {[...Array(5 - (seconds % 5) - 1)].map((_, i) => ( +
+ ))} +
+
+ ); } diff --git a/src/css/custom.css b/src/css/custom.css index f7f864a58f..3678f2f341 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -49,5 +49,5 @@ html { } .img_sponsor { - @apply h-full px-[10px] max-h-[120px] inline; + @apply p-[10px] max-h-[99px] max-w-[330px] inline; }