diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx index 362c41313..7f8f86b32 100644 --- a/src/components/Loading.tsx +++ b/src/components/Loading.tsx @@ -1,14 +1,46 @@ import { useEffect, useState } from 'react' +// import { +// ConnectingType, +// ConnectingTypeGroup, +// DisconnectingType, +// EngineCommandManagerEvents, +// EngineConnectionEvents, +// EngineConnectionStateType, +// ErrorType, +// initialConnectingTypeGroupState, +// } from '../lang/std/engineConnection' +// import { engineCommandManager } from '../lib/singletons' + +// Sorted by severity +enum Error { + Unset = 0, + LongLoadingTime, + BadAuthToken, + TooManyConnections, +} + +const errorText: Record = { + [Error.Unset]: "", + [Error.LongLoadingTime]: "Loading is taking longer than expected...", + [Error.BadAuthToken]: "Your authorization token is not valid; please login again.", + [Error.TooManyConnections]: "There are too many connections.", +} + const Loading = ({ children }: React.PropsWithChildren) => { - const [hasLongLoadTime, setHasLongLoadTime] = useState(false) + const [error, setError] = useState(Error.Unset) + useEffect(() => { + // Don't set long loading time if there's a more severe error + if (error > Error.LongLoadingTime) return + const timer = setTimeout(() => { - setHasLongLoadTime(true) + setError(Error.LongLoadingTime) }, 4000) return () => clearTimeout(timer) - }, [setHasLongLoadTime]) + }, [error, setError]) + return (
{

- Loading is taking longer than expected. + { errorText[error] }

)