From f5a9b80052388294f1600974778f4ca1ca8cb4fe Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 7 Jun 2021 10:51:27 +0100 Subject: [PATCH] Merge pull request #4087 from overleaf/hb-chat-error-boundary Chat error boundary GitOrigin-RevId: 19bc6ee243d9b30510f2164462760bad04516ec3 --- .../web/frontend/extracted-translations.json | 2 + .../chat/components/chat-fallback-error.js | 29 ++++++++++++++ .../js/features/chat/components/chat-pane.js | 14 ++++++- .../js/features/chat/context/chat-context.js | 37 +++++++++++++++--- .../frontend/stylesheets/app/editor/chat.less | 9 +++++ services/web/locales/en.json | 2 + .../chat/components/chat-pane.test.js | 28 +++++++++++++- .../chat/context/chat-context.test.js | 38 +++++++++++++++++++ 8 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 services/web/frontend/js/features/chat/components/chat-fallback-error.js diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 4a4fdd94f9..35f272b27e 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -32,6 +32,7 @@ "change_owner": "", "change_project_owner": "", "chat": "", + "chat_error": "", "checking_dropbox_status": "", "checking_project_github_status": "", "clear_cached_files": "", @@ -241,6 +242,7 @@ "recent_commits_in_github": "", "recompile": "", "recompile_from_scratch": "", + "reconnect": "", "reference_error_relink_hint": "", "refresh": "", "refresh_page_after_linking_dropbox": "", diff --git a/services/web/frontend/js/features/chat/components/chat-fallback-error.js b/services/web/frontend/js/features/chat/components/chat-fallback-error.js new file mode 100644 index 0000000000..c79b0ed439 --- /dev/null +++ b/services/web/frontend/js/features/chat/components/chat-fallback-error.js @@ -0,0 +1,29 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { useTranslation } from 'react-i18next' +import { Button, Alert } from 'react-bootstrap' + +function ChatFallbackError({ reconnect }) { + const { t } = useTranslation() + + return ( + + ) +} + +ChatFallbackError.propTypes = { + reconnect: PropTypes.any, +} + +export default ChatFallbackError diff --git a/services/web/frontend/js/features/chat/components/chat-pane.js b/services/web/frontend/js/features/chat/components/chat-pane.js index ba40859124..a67670874f 100644 --- a/services/web/frontend/js/features/chat/components/chat-pane.js +++ b/services/web/frontend/js/features/chat/components/chat-pane.js @@ -5,10 +5,12 @@ import { useTranslation } from 'react-i18next' import MessageList from './message-list' import MessageInput from './message-input' import InfiniteScroll from './infinite-scroll' +import ChatFallbackError from './chat-fallback-error' import Icon from '../../../shared/components/icon' import { useLayoutContext } from '../../../shared/context/layout-context' import { useApplicationContext } from '../../../shared/context/application-context' import withErrorBoundary from '../../../infrastructure/error-boundary' +import { FetchError } from '../../../infrastructure/fetch-json' import { useChatContext } from '../context/chat-context' function ChatPane() { @@ -26,8 +28,10 @@ function ChatPane() { atEnd, loadInitialMessages, loadMoreMessages, + reset, sendMessage, markMessagesAsRead, + error, } = useChatContext() useEffect(() => { @@ -43,6 +47,14 @@ function ChatPane() { 0 ) + if (error) { + // let user try recover from fetch errors + if (error instanceof FetchError) { + return + } + throw error + } + return (