diff --git a/resources/scripts/components/dashboard/ServerRow.tsx b/resources/scripts/components/dashboard/ServerRow.tsx index 7373fa246..84b8a7609 100644 --- a/resources/scripts/components/dashboard/ServerRow.tsx +++ b/resources/scripts/components/dashboard/ServerRow.tsx @@ -41,8 +41,9 @@ const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | unde export default ({ server, className }: { server: Server; className?: string }) => { const interval = useRef(null); - const [ stats, setStats ] = useState(null); const [ statsError, setStatsError ] = useState(false); + const [ isSuspended, setIsSuspended ] = useState(server.isSuspended); + const [ stats, setStats ] = useState(null); const getStats = () => { setStatsError(false); @@ -55,6 +56,14 @@ export default ({ server, className }: { server: Server; className?: string }) = }; useEffect(() => { + setIsSuspended(stats?.isSuspended || server.isSuspended); + }, [ stats?.isSuspended, server.isSuspended ]); + + useEffect(() => { + // Don't waste a HTTP request if there is nothing important to show to the user because + // the server is suspended. + if (isSuspended) return; + getStats().then(() => { // @ts-ignore interval.current = setInterval(() => getStats(), 20000); @@ -63,7 +72,7 @@ export default ({ server, className }: { server: Server; className?: string }) = return () => { interval.current && clearInterval(interval.current); }; - }, []); + }, [ isSuspended ]); const alarms = { cpu: false, memory: false, disk: false }; if (stats) { @@ -101,9 +110,13 @@ export default ({ server, className }: { server: Server; className?: string }) =

- {!stats ? - !statsError ? - + {(!stats || isSuspended) ? + isSuspended ? +
+ + {server.isSuspended ? 'Suspended' : 'Connection Error'} + +
: server.isInstalling ?
@@ -112,11 +125,7 @@ export default ({ server, className }: { server: Server; className?: string }) =
: -
- - {server.isSuspended ? 'Suspended' : 'Connection Error'} - -
+ :