From 7177652043ce8099d23ded18a17755faf2be051f Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 26 Jun 2024 22:07:43 +0100 Subject: [PATCH] Auto refresh bots and servers page --- bootstrap/manager/src/ui/src/pages/Bots.jsx | 9 ++++++++- bootstrap/manager/src/ui/src/pages/Servers.jsx | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bootstrap/manager/src/ui/src/pages/Bots.jsx b/bootstrap/manager/src/ui/src/pages/Bots.jsx index a546b7a..c8236ee 100644 --- a/bootstrap/manager/src/ui/src/pages/Bots.jsx +++ b/bootstrap/manager/src/ui/src/pages/Bots.jsx @@ -13,15 +13,22 @@ function Bots () { const navigate = useNavigate() const { state } = useLocation() - useEffect(() => { + const updateBots = () => { fetch('/api/bots').then((res) => res.json()).then((data) => { setBots(data) }) + } + + useEffect(() => { + updateBots() // Clear the error state when the component mounts if (state && state.error) { window.history.replaceState({}, '') } + + const interval = setInterval(updateBots, 2500) // Update every 2.5 seconds + return () => clearInterval(interval) }, []) const addBot = () => { diff --git a/bootstrap/manager/src/ui/src/pages/Servers.jsx b/bootstrap/manager/src/ui/src/pages/Servers.jsx index f393938..133b28e 100644 --- a/bootstrap/manager/src/ui/src/pages/Servers.jsx +++ b/bootstrap/manager/src/ui/src/pages/Servers.jsx @@ -13,15 +13,22 @@ function Servers () { const navigate = useNavigate() const { state } = useLocation() - useEffect(() => { + const updateServers = () => { fetch('/api/servers').then((res) => res.json()).then((data) => { setServers(data) }) + } + + useEffect(() => { + updateServers() // Clear the error state when the component mounts if (state && state.error) { window.history.replaceState({}, '') } + + const interval = setInterval(updateServers, 2500) // Update every 2.5 seconds + return () => clearInterval(interval) }, []) const addServer = () => {