Skip to content

Commit

Permalink
fix: editorJS
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid-80 committed Jul 26, 2024
1 parent 716053d commit cc04f6d
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/app/workspace/_components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,13 @@ const Editor = forwardRef((props: EditorProps, ref) => {
);

useEffect(() => {
if (props.fileData) {
if(editorInstanceRef === null){
initEditor();
}

return () => {
if (editorInstanceRef.current) {
editorInstanceRef.current.isReady
.then(() => {
editorInstanceRef.current?.destroy();
editorInstanceRef.current = null;
})
.catch((error) => {
console.error("Error while destroying EditorJS instance:", error);
});
}
editorInstanceRef?.current?.destroy();
editorInstanceRef.current = null;
};
}, [props.fileData]);

Expand All @@ -107,17 +99,6 @@ const Editor = forwardRef((props: EditorProps, ref) => {
}, [props.onSaveTrigger]);

const initEditor = () => {
if (editorInstanceRef.current) {
editorInstanceRef.current.isReady
.then(() => {
editorInstanceRef.current?.destroy();
editorInstanceRef.current = null;
})
.catch((error) => {
console.error("Error while destroying EditorJS instance:", error);
});
}

editorInstanceRef.current = new EditorJS({
tools: {
header: {
Expand All @@ -130,7 +111,7 @@ const Editor = forwardRef((props: EditorProps, ref) => {
},
},
list: {
class: List,
class: List as unknown as ToolConstructable,
inlineToolbar: true,
config: {
defaultStyle: "unordered",
Expand Down Expand Up @@ -181,8 +162,6 @@ const Editor = forwardRef((props: EditorProps, ref) => {
editorInstanceRef.current
.save()
.then(async (outputData) => {
console.log(outputData);

try {
const saveUrl = props.fileData.filePrivate
? saveWorkspacePrivateUrl
Expand Down

0 comments on commit cc04f6d

Please sign in to comment.