From f4faa1e0b2a09e231aebd1a3b4f024e5ddb57bd9 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Tue, 14 May 2024 15:49:50 +0530 Subject: [PATCH] chore: save description_html as well --- packages/editor/core/src/hooks/use-editor.tsx | 4 ++++ packages/editor/core/src/hooks/use-read-only-editor.tsx | 4 ++++ packages/editor/core/src/types/editor-ref-api.ts | 1 + .../editor/document-editor/src/hooks/use-document-editor.ts | 4 ++-- .../document-editor/src/providers/collaboration-provider.ts | 4 ++-- packages/editor/document-editor/src/ui/index.tsx | 3 +-- web/components/pages/editor/editor-body.tsx | 4 ++-- .../[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx | 3 ++- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/editor/core/src/hooks/use-editor.tsx b/packages/editor/core/src/hooks/use-editor.tsx index 411c113e7..2d2e1662a 100644 --- a/packages/editor/core/src/hooks/use-editor.tsx +++ b/packages/editor/core/src/hooks/use-editor.tsx @@ -178,6 +178,10 @@ export const useEditor = ({ const markdownOutput = editorRef.current?.storage.markdown.getMarkdown(); return markdownOutput; }, + getHTML: (): string => { + const htmlOutput = editorRef.current?.getHTML() ?? "

"; + return htmlOutput; + }, scrollSummary: (marking: IMarking): void => { if (!editorRef.current) return; scrollSummary(editorRef.current, marking); diff --git a/packages/editor/core/src/hooks/use-read-only-editor.tsx b/packages/editor/core/src/hooks/use-read-only-editor.tsx index 9607586d8..8b16d1e76 100644 --- a/packages/editor/core/src/hooks/use-read-only-editor.tsx +++ b/packages/editor/core/src/hooks/use-read-only-editor.tsx @@ -68,6 +68,10 @@ export const useReadOnlyEditor = ({ const markdownOutput = editorRef.current?.storage.markdown.getMarkdown(); return markdownOutput; }, + getHTML: (): string => { + const htmlOutput = editorRef.current?.getHTML() ?? "

"; + return htmlOutput; + }, scrollSummary: (marking: IMarking): void => { if (!editorRef.current) return; scrollSummary(editorRef.current, marking); diff --git a/packages/editor/core/src/types/editor-ref-api.ts b/packages/editor/core/src/types/editor-ref-api.ts index df5df2c7b..4eed815d6 100644 --- a/packages/editor/core/src/types/editor-ref-api.ts +++ b/packages/editor/core/src/types/editor-ref-api.ts @@ -3,6 +3,7 @@ import { EditorMenuItemNames } from "src/ui/menus/menu-items"; export type EditorReadOnlyRefApi = { getMarkDown: () => string; + getHTML: () => string; clearEditor: () => void; setEditorValue: (content: string) => void; scrollSummary: (marking: IMarking) => void; diff --git a/packages/editor/document-editor/src/hooks/use-document-editor.ts b/packages/editor/document-editor/src/hooks/use-document-editor.ts index e5e615cdd..34723cd63 100644 --- a/packages/editor/document-editor/src/hooks/use-document-editor.ts +++ b/packages/editor/document-editor/src/hooks/use-document-editor.ts @@ -14,7 +14,7 @@ type DocumentEditorProps = { fileHandler: TFileHandler; value: Uint8Array; editorClassName: string; - onChange: (binaryString: string, html: string) => void; + onChange: (binaryString: string) => void; extensions?: any; editorProps?: EditorProps; forwardedRef?: React.MutableRefObject; @@ -53,7 +53,7 @@ export const useDocumentEditor = ({ ); const yDoc = useMemo(() => { - if (value.byteLength !== 0) Y.applyUpdate(provider.document, value); + if (value.byteLength > 0) Y.applyUpdate(provider.document, value); return provider.document; }, [value, provider.document]); console.log("yDoc", yDoc); diff --git a/packages/editor/document-editor/src/providers/collaboration-provider.ts b/packages/editor/document-editor/src/providers/collaboration-provider.ts index 048e54e5a..87270284a 100644 --- a/packages/editor/document-editor/src/providers/collaboration-provider.ts +++ b/packages/editor/document-editor/src/providers/collaboration-provider.ts @@ -12,7 +12,7 @@ export interface CompleteCollaboratorProviderConfiguration { /** * onChange callback */ - onChange: (binaryString: string, html: string) => void; + onChange: (binaryString: string) => void; } export type CollaborationProviderConfiguration = Required> & @@ -60,7 +60,7 @@ export class CollaborationProvider { const base64Doc = Buffer.from(docAsUint8Array).toString("base64"); // const base64Doc = Buffer.from(update).toString("base64"); - this.configuration.onChange?.(base64Doc, "

"); + this.configuration.onChange?.(base64Doc); this.timeoutId = null; }, 2000); } diff --git a/packages/editor/document-editor/src/ui/index.tsx b/packages/editor/document-editor/src/ui/index.tsx index 738996d76..246edacfc 100644 --- a/packages/editor/document-editor/src/ui/index.tsx +++ b/packages/editor/document-editor/src/ui/index.tsx @@ -19,7 +19,7 @@ interface IDocumentEditor { handleEditorReady?: (value: boolean) => void; containerClassName?: string; editorClassName?: string; - onChange: (binaryString: string, html: string) => void; + onChange: (binaryString: string) => void; forwardedRef?: React.MutableRefObject; mentionHandler: { highlights: () => Promise; @@ -46,7 +46,6 @@ const DocumentEditor = (props: IDocumentEditor) => { } = props; // states const [hideDragHandleOnMouseLeave, setHideDragHandleOnMouseLeave] = useState<() => void>(() => {}); - // this essentially sets the hideDragHandle function from the DragAndDrop extension as the Plugin // loads such that we can invoke it from react when the cursor leaves the container const setHideDragHandleFunction = (hideDragHandlerFromDragDrop: () => void) => { diff --git a/web/components/pages/editor/editor-body.tsx b/web/components/pages/editor/editor-body.tsx index de08ca4fd..0a9fa48ec 100644 --- a/web/components/pages/editor/editor-body.tsx +++ b/web/components/pages/editor/editor-body.tsx @@ -32,7 +32,7 @@ const fileService = new FileService(); type Props = { editorRef: React.RefObject; readOnlyEditorRef: React.RefObject; - handleDescriptionUpdate: (binaryString: string, descriptionHTML: string) => Promise; + handleDescriptionUpdate: (binaryString: string) => Promise; markings: IMarking[]; pageStore: IPageStore; sidePeekVisible: boolean; @@ -98,7 +98,7 @@ export const PageEditorBody: React.FC = observer((props) => { updateMarkings(description_html ?? "

"); }, [description_html, updateMarkings]); - if (pageDescription === undefined || pageId === undefined || !pageDescriptionYJS) return ; + if (pageId === undefined || !descriptionYJS || !pageDescriptionYJS) return ; return (
diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx index 56095b27c..91b1b8a63 100644 --- a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx +++ b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx @@ -52,8 +52,9 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { ); const handleDescriptionChange = useCallback( - async (binaryString: string, descriptionHTML: string) => { + async (binaryString: string) => { setIsSubmitting("submitting"); + const descriptionHTML = editorRef.current?.getHTML() ?? "

"; await updateDescription(binaryString, descriptionHTML).finally(() => setIsSubmitting("saved")); }, [setIsSubmitting, updateDescription]