From 337221cdd6f144d74a21007db2e9649d91d0a038 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 30 Jan 2021 01:10:27 +0000 Subject: [PATCH] Rate limit API when we're not broadcasting. --- src/navbar/timelord.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/navbar/timelord.tsx b/src/navbar/timelord.tsx index 8eb2ea4..8cbc1d7 100644 --- a/src/navbar/timelord.tsx +++ b/src/navbar/timelord.tsx @@ -36,15 +36,20 @@ export function Timelord() { } const broadcastState = useSelector((state: RootState) => state.broadcast); - const [source, setSource] = useState({ id: 0, name: "Unknown" }); + const [source, setSource] = useState({ id: -1, name: "Loading" }); const [isSilence, setSilence] = useState(false); - useInterval(async () => { - setSource(await getSource()); - }, 3000); + useInterval( + async () => { + setSource(await getSource()); + }, + broadcastState.stage === "REGISTERED" ? 3000 : 10000 + ); useInterval(async () => { - setSilence(await getSilence()); + broadcastState.stage === "REGISTERED" + ? setSilence(await getSilence()) + : setSilence(false); }, 3000); return ( @@ -71,10 +76,12 @@ export function Timelord() { ) : isSilence ? ( SILENCE DETECTED ) : ( - - {source.name} -  is On Air - + source.id > -1 && ( + + {source.name} +  is On Air + + ) )} );