diff --git a/services/web/app/views/project/editor/meta.pug b/services/web/app/views/project/editor/meta.pug index e639a57a48..37d7a06461 100644 --- a/services/web/app/views/project/editor/meta.pug +++ b/services/web/app/views/project/editor/meta.pug @@ -37,8 +37,12 @@ meta(name="ol-hasTrackChangesFeature", data-type="boolean" content=hasTrackChang meta(name="ol-inactiveTutorials", data-type="json" content=user.inactiveTutorials) meta(name="ol-projectTags" data-type="json" content=projectTags) meta(name="ol-linkSharingWarning" data-type="boolean" content=linkSharingWarning) + +// translations for the loading page, before i18n has loaded in the client meta(name="ol-loadingText", data-type="string" content=translate("loading")) +meta(name="ol-translationIoNotLoaded", data-type="string" content=translate("could_not_connect_to_websocket_server")) meta(name="ol-translationLoadErrorMessage", data-type="string" content=translate("could_not_load_translations")) +meta(name="ol-translationUnableToJoin", data-type="string" content=translate("could_not_connect_to_collaboration_server")) if (settings.overleaf != null) meta(name="ol-overallThemes" data-type="json" content=overallThemes) diff --git a/services/web/frontend/js/features/ide-react/components/loading-error.tsx b/services/web/frontend/js/features/ide-react/components/loading-error.tsx new file mode 100644 index 0000000000..2e73e7dd56 --- /dev/null +++ b/services/web/frontend/js/features/ide-react/components/loading-error.tsx @@ -0,0 +1,26 @@ +import { FC } from 'react' +import { ConnectionError } from '@/features/ide-react/connection/types/connection-state' +import getMeta from '@/utils/meta' + +// NOTE: i18n translations might not be loaded in the client at this point, +// so these translations have to be loaded from meta tags +export const LoadingError: FC<{ + connectionStateError: ConnectionError | '' + i18nError?: Error +}> = ({ connectionStateError, i18nError }) => { + if (connectionStateError) { + switch (connectionStateError) { + case 'io-not-loaded': + return <>{getMeta('ol-translationIoNotLoaded')}> + + case 'unable-to-join': + return <>{getMeta('ol-translationUnableToJoin')}> + } + } + + if (i18nError) { + return <>{getMeta('ol-translationLoadErrorMessage')}> + } + + return null +} diff --git a/services/web/frontend/js/features/ide-react/components/loading.tsx b/services/web/frontend/js/features/ide-react/components/loading.tsx index 0d6e6815e2..cddab30c0e 100644 --- a/services/web/frontend/js/features/ide-react/components/loading.tsx +++ b/services/web/frontend/js/features/ide-react/components/loading.tsx @@ -4,6 +4,7 @@ import useWaitForI18n from '@/shared/hooks/use-wait-for-i18n' import getMeta from '@/utils/meta' import { useConnectionContext } from '../context/connection-context' import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context' +import { LoadingError } from './loading-error' type Part = 'initial' | 'render' | 'connection' | 'translations' | 'project' @@ -54,21 +55,6 @@ export const Loading: FC<{ } }, [projectJoined]) - const getLoadingScreenError = (): string => { - if (connectionState.error) { - // NOTE: translations not ready yet - return connectionState.error === 'io-not-loaded' - ? 'Could not connect to websocket server :(' - : connectionState.error - } - - if (i18n.error) { - return getMeta('ol-translationLoadErrorMessage') - } - - return '' - } - // Use loading text from the server, because i18n will not be ready initially const label = getMeta('ol-loadingText') @@ -82,7 +68,12 @@ export const Loading: FC<{ hasError={hasError} /> {hasError && ( -
{getLoadingScreenError()}
+
+