diff --git a/editors/editoria/src/layout/EditoriaLayout.js b/editors/editoria/src/layout/EditoriaLayout.js index 167a37bc4e229a9253e0e5971607bf7d74340f55..c32556c22e91dc6f7a5ead0b0381276e03741563 100644 --- a/editors/editoria/src/layout/EditoriaLayout.js +++ b/editors/editoria/src/layout/EditoriaLayout.js @@ -1,10 +1,10 @@ -import React, { useContext } from 'react'; +import React, { useContext, useState, useCallback, useEffect } from 'react'; import styled, { css, ThemeProvider } from 'styled-components'; import PanelGroup from 'react-panelgroup'; import { DocumentHelpers } from 'wax-prosemirror-utilities'; import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core'; import { grid, th } from '@pubsweet/ui-toolkit'; - +import { debounce } from 'lodash'; import { cokoTheme } from '../theme'; import EditorElements from './EditorElements'; @@ -150,7 +150,7 @@ const onResizeEnd = arr => { notesHeight = arr[1].size; }; -const hasNotes = main => { +const getNotes = main => { const notes = DocumentHelpers.findChildrenByType( main.state.doc, main.state.schema.nodes.footnote, @@ -170,8 +170,22 @@ const EditoriaLayout = ({ editor }) => { view: { main }, } = useContext(WaxContext); - const notes = main && hasNotes(main); - const showNotes = notes && !!notes.length && notes.length > 0; + const notes = main && getNotes(main); + + const [hasNotes, setHasNotes] = useState( + notes && !!notes.length && notes.length > 0, + ); + + const showNotes = () => { + setHasNotes(notes && !!notes.length && notes.length > 0); + }; + + const delayedShowedNotes = useCallback( + setTimeout(() => showNotes(), 100), + [], + ); + + useEffect(() => {}, [delayedShowedNotes]); return ( <ThemeProvider theme={cokoTheme}> @@ -190,7 +204,7 @@ const EditoriaLayout = ({ editor }) => { direction="column" panelWidths={[ { size: surfaceHeight, resize: 'stretch' }, - { size: notesHeight, resize: 'stretch' }, + { size: notesHeight, resize: 'resize' }, ]} onResizeEnd={onResizeEnd} > @@ -201,7 +215,7 @@ const EditoriaLayout = ({ editor }) => { </CommentsContainer> </WaxSurfaceScroll> - {showNotes && ( + {hasNotes && ( <NotesAreaContainer> <NotesContainer id="notes-container"> <NotesArea view={main} /> diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index cc569e9c8299fe0f5d3a458278600239979ce53a..8f3233b798f5d2facbbadedfa6b15100b5d59e3d 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -19,7 +19,7 @@ export default ({ node, view }) => { const noteId = node.attrs.id; let noteView; let updateMainView = true; - + console.log(context); useEffect(() => { noteView = new EditorView( { mount: editorRef.current },