Skip to content
Snippets Groups Projects
Commit 589a4164 authored by chris's avatar chris
Browse files

fix notes rerender

parent 2e2fe9a1
No related branches found
No related tags found
No related merge requests found
...@@ -6,19 +6,23 @@ import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core'; ...@@ -6,19 +6,23 @@ import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core';
import NoteEditor from './NoteEditor'; import NoteEditor from './NoteEditor';
export default ({ view }) => { export default ({ view }) => {
if (typeof view === 'undefined') return null;
const context = useContext(WaxContext); const context = useContext(WaxContext);
if (typeof view === 'undefined') return null;
const {
pmViews: { main },
} = context;
const { const {
state: { tr }, state: { tr },
} = view; } = main;
const [notes, setNotes] = useState([]); const [notes, setNotes] = useState([]);
const cleanUpNoteViews = () => { const cleanUpNoteViews = () => {
if (view) { if (main) {
const currentNotes = DocumentHelpers.findChildrenByType( const currentNotes = DocumentHelpers.findChildrenByType(
view.state.doc, main.state.doc,
view.state.schema.nodes.footnote, main.state.schema.nodes.footnote,
true, true,
); );
if (notes.length > currentNotes.length) { if (notes.length > currentNotes.length) {
...@@ -28,7 +32,7 @@ export default ({ view }) => { ...@@ -28,7 +32,7 @@ export default ({ view }) => {
}); });
tr.setMeta('notesChanged', true); tr.setMeta('notesChanged', true);
view.dispatch(tr); main.dispatch(tr);
// const newView = Object.keys(view).reduce((object, key) => { // const newView = Object.keys(view).reduce((object, key) => {
// if (key !== difference[0].node.attrs.id) { // if (key !== difference[0].node.attrs.id) {
...@@ -41,12 +45,12 @@ export default ({ view }) => { ...@@ -41,12 +45,12 @@ export default ({ view }) => {
}; };
useDeepCompareEffect(() => { useDeepCompareEffect(() => {
setNotes(updateNotes(view)); setNotes(updateNotes(context.pmViews.main));
cleanUpNoteViews(); cleanUpNoteViews();
}, [updateNotes(view)]); }, [updateNotes(main)]);
const noteComponent = useMemo( const noteComponent = useMemo(
() => <NoteEditor notes={notes} view={view} />, () => <NoteEditor notes={notes} view={main} />,
[notes], [notes],
); );
return <>{noteComponent}</>; return <>{noteComponent}</>;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment