From 4617b4881886c2d802cfdb457ff07c7ec5f478a6 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 31 May 2023 01:51:05 +0300 Subject: [PATCH] adding auto refresh, scroll to top after click on streamers --- src/components/Streamers.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/Streamers.tsx b/src/components/Streamers.tsx index 1d84bb6..1e0ea7a 100644 --- a/src/components/Streamers.tsx +++ b/src/components/Streamers.tsx @@ -5,19 +5,39 @@ import { Link } from "react-router-dom"; export const Streamers = () => { const [streamers, setStreamers] = React.useState([]); + const getStreamers = async () => { + const data = await (window as any).electronAPI?.getStreamers(); + if (!data) return; + setStreamers(data?.data); + }; + React.useEffect(() => { + let interval: any; + (async () => { try { - const data = await (window as any).electronAPI?.getStreamers(); - if (!data) return; - setStreamers(data?.data); + getStreamers(); + + interval = setInterval(() => { + getStreamers(); + }, 10000); } catch (err) { console.error(err); toast.error("Failed to get streamers"); } })(); + + return () => { + clearInterval(interval); + }; }, []); + const scrollToTop = () => { + window.scrollTo({ + top: 0, + }); + }; + return (