Skip to content

Commit

Permalink
Auto refresh bots and servers page
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jun 26, 2024
1 parent 8243759 commit 7177652
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion bootstrap/manager/src/ui/src/pages/Bots.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
9 changes: 8 additions & 1 deletion bootstrap/manager/src/ui/src/pages/Servers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 7177652

Please sign in to comment.