diff --git a/front/src/components/collaborative/CollaborativeEditorStatus.jsx b/front/src/components/collaborative/CollaborativeEditorStatus.jsx index f170aaa26..206778074 100644 --- a/front/src/components/collaborative/CollaborativeEditorStatus.jsx +++ b/front/src/components/collaborative/CollaborativeEditorStatus.jsx @@ -9,7 +9,6 @@ import PropTypes from 'prop-types' import React, { useCallback } from 'react' import { StopCircle } from 'react-feather' import { useTranslation } from 'react-i18next' -import { shallowEqual, useSelector } from 'react-redux' import { useHistory } from 'react-router-dom' import { useMutation } from '../../hooks/graphql.js' import CollaborativeEditorWebSocketStatus from './CollaborativeEditorWebSocketStatus.jsx' @@ -22,21 +21,12 @@ import styles from './CollaborativeEditorStatus.module.scss' export default function CollaborativeEditorStatus({ articleId, websocketStatus, - collaborativeSessionCreatorId, + collaborativeSessionState, }) { const { t } = useTranslation() const mutation = useMutation() const { setToast } = useToasts() const history = useHistory() - const activeUser = useSelector( - (state) => ({ - _id: state.activeUser._id, - email: state.activeUser.email, - displayName: state.activeUser.displayName, - username: state.activeUser.username, - }), - shallowEqual - ) const { visible: collaborativeSessionEndVisible, @@ -74,18 +64,24 @@ export default function CollaborativeEditorStatus({
- +
- + {websocketStatus === 'connected' && + collaborativeSessionState === 'started' && ( + + )} + Connecting + + + ) + } return ( <> {status === 'connected' && ( @@ -19,7 +28,8 @@ export default function CollaborativeEditorWebSocketStatus({ status }) { )} {status === 'connecting' && ( - Connecting + Connecting + )} @@ -27,5 +37,6 @@ export default function CollaborativeEditorWebSocketStatus({ status }) { } CollaborativeEditorWebSocketStatus.propTypes = { + state: PropTypes.string.isRequired, status: PropTypes.string.isRequired, } diff --git a/front/src/components/collaborative/CollaborativeEditorWebSocketStatus.module.scss b/front/src/components/collaborative/CollaborativeEditorWebSocketStatus.module.scss index 08d048fd3..1b83bffa8 100644 --- a/front/src/components/collaborative/CollaborativeEditorWebSocketStatus.module.scss +++ b/front/src/components/collaborative/CollaborativeEditorWebSocketStatus.module.scss @@ -1,3 +1,28 @@ .dot { font-size: 0.8rem !important; + + :global { + .label { + display: flex; + gap: 0.25rem; + } + } +} + +.loadingIndicator { + height: 1em; + width: 1em; + animation: rotation 2.5s; + animation-iteration-count: infinite; + animation-timing-function: linear; + flex-shrink: 0; +} + +@keyframes rotation { + from { + transform: rotate(0deg); + } + to { + transform: rotate(359deg); + } } diff --git a/front/src/components/collaborative/CollaborativeTextEditor.jsx b/front/src/components/collaborative/CollaborativeTextEditor.jsx index c0464e1bc..303d198be 100644 --- a/front/src/components/collaborative/CollaborativeTextEditor.jsx +++ b/front/src/components/collaborative/CollaborativeTextEditor.jsx @@ -50,6 +50,7 @@ export default function CollaborativeTextEditor({ const connectingRef = useRef(false) const [dynamicStyles, setDynamicStyles] = useState('') const [websocketStatus, setWebsocketStatus] = useState('') + const [collaborativeSessionState, setCollaborativeSessionState] = useState('') const [yText, setYText] = useState(null) const [awareness, setAwareness] = useState(null) const { websocketEndpoint } = useSelector( @@ -75,7 +76,9 @@ export default function CollaborativeTextEditor({ const options = useMemo( () => ({ automaticLayout: true, - readOnly: websocketStatus !== 'connected', + readOnly: + websocketStatus !== 'connected' || + collaborativeSessionState !== 'started', contextmenu: websocketStatus === 'connected', autoClosingBrackets: 'never', wordBasedSuggestions: false, @@ -143,8 +146,18 @@ export default function CollaborativeTextEditor({ [setWebsocketStatus] ) + const handleEditorDidMount = useCallback( + (editor) => { + editorRef.current = editor + new MonacoBinding(yText, editor.getModel(), new Set([editor]), awareness) + }, + [yText, awareness] + ) + useEffect(() => { - if (connectingRef.current) return + if (connectingRef.current) { + return + } connectingRef.current = true const { awareness, @@ -163,29 +176,19 @@ export default function CollaborativeTextEditor({ handleUpdateArticleStructureAndStats({ text: yText.toString() }) }) yState.observe(function () { + setCollaborativeSessionState(yState.toString()) onCollaborativeSessionStateUpdated({ state: yState.toString() }) }) setAwareness(awareness) setYText(yText) return () => { - try { - awareness.destroy() - wsProvider.disconnect() - wsProvider.destroy() - } catch (err) { - // try to disconnect... - } + connectingRef.current = false + awareness.destroy() + wsProvider.disconnect() + wsProvider.destroy() } }, [collaborativeSessionId, websocketEndpoint, writerInfo]) - const handleEditorDidMount = useCallback( - (editor) => { - editorRef.current = editor - new MonacoBinding(yText, editor.getModel(), new Set([editor]), awareness) - }, - [yText, awareness] - ) - useEffect(() => { const line = editorCursorPosition.lineNumber const editor = editorRef.current @@ -204,6 +207,7 @@ export default function CollaborativeTextEditor({ @@ -212,7 +216,6 @@ export default function CollaborativeTextEditor({ className={styles.editor} defaultLanguage="markdown" onMount={handleEditorDidMount} - on /> )