From b004f1e21d11c65084ac2210056a05e0909c7649 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 28 Oct 2021 10:00:16 +0200 Subject: [PATCH] Use the new storage feature for the `CollaborationCursor` extension (#2096) * extension-collaboration-cursor: make use of the new storage feature, deprecate users command and onUsers callback, clean up * docs: update the jobs page --- .../CollaborativeEditing/React/index.jsx | 10 ++-- .../CollaborativeEditing/Vue/index.vue | 10 +--- docs/api/extensions/collaboration-cursor.md | 10 ++-- docs/jobs.md | 10 ++-- .../src/collaboration-cursor.ts | 52 +++++++++++++------ 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/demos/src/Examples/CollaborativeEditing/React/index.jsx b/demos/src/Examples/CollaborativeEditing/React/index.jsx index 23aa99046..7970eb490 100644 --- a/demos/src/Examples/CollaborativeEditing/React/index.jsx +++ b/demos/src/Examples/CollaborativeEditing/React/index.jsx @@ -65,7 +65,6 @@ const getInitialUser = () => { export default () => { const [status, setStatus] = useState('connecting') - const [users, setUsers] = useState([]) const [currentUser, setCurrentUser] = useState(getInitialUser) const editor = useEditor({ @@ -84,9 +83,6 @@ export default () => { }), CollaborationCursor.configure({ provider: websocketProvider, - onUpdate: updatedUsers => { - setUsers(updatedUsers) - }, }), ], }) @@ -96,7 +92,7 @@ export default () => { const indexeddbProvider = new IndexeddbPersistence(room, ydoc) indexeddbProvider.on('synced', () => { - console.log('Loaded content from database …') + console.log('Loaded content from database …') }) // Update status changes @@ -109,7 +105,7 @@ export default () => { useEffect(() => { if (editor && currentUser) { localStorage.setItem('currentUser', JSON.stringify(currentUser)) - editor.chain().focus().user(currentUser).run() + editor.chain().focus().updateUser(currentUser).run() } }, [editor, currentUser]) @@ -128,7 +124,7 @@ export default () => {
{status === 'connected' - ? `${users.length} user${users.length === 1 ? '' : 's'} online in ${room}` + ? `${editor.storage.collaborationCursor.users.length} user${editor.storage.collaborationCursor.users.length === 1 ? '' : 's'} online in ${room}` : 'offline'}
diff --git a/demos/src/Examples/CollaborativeEditing/Vue/index.vue b/demos/src/Examples/CollaborativeEditing/Vue/index.vue index 9bb26298c..810f562b6 100644 --- a/demos/src/Examples/CollaborativeEditing/Vue/index.vue +++ b/demos/src/Examples/CollaborativeEditing/Vue/index.vue @@ -5,7 +5,7 @@