loading-error.tsx 857 B

123456789101112131415161718192021222324
  1. import { FC } from 'react'
  2. import { ConnectionError } from '@/features/ide-react/connection/types/connection-state'
  3. import getMeta from '@/utils/meta'
  4. const errorMessages = {
  5. 'io-not-loaded': 'ol-translationIoNotLoaded',
  6. 'unable-to-join': 'ol-translationUnableToJoin',
  7. 'i18n-error': 'ol-translationLoadErrorMessage',
  8. } as const
  9. const isHandledCode = (key: string): key is keyof typeof errorMessages =>
  10. key in errorMessages
  11. export type LoadingErrorProps = {
  12. errorCode: ConnectionError | 'i18n-error' | ''
  13. }
  14. // NOTE: i18n translations might not be loaded in the client at this point,
  15. // so these translations have to be loaded from meta tags
  16. export const LoadingError: FC<LoadingErrorProps> = ({ errorCode }) => {
  17. return isHandledCode(errorCode) ? (
  18. <p className="loading-screen-error">{getMeta(errorMessages[errorCode])}</p>
  19. ) : null
  20. }