fix: update fallback logic for newly created pages (#6345)
This commit is contained in:
parent
71ebe5ca36
commit
ac14d57f8b
1 changed files with 24 additions and 17 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useCallback, useEffect } from "react";
|
||||
// plane editor
|
||||
import { EditorRefApi } from "@plane/editor";
|
||||
import { EditorRefApi, getBinaryDataFromDocumentEditorHTMLString } from "@plane/editor";
|
||||
// plane types
|
||||
import { TDocumentPayload } from "@plane/types";
|
||||
// hooks
|
||||
|
|
@ -8,7 +8,7 @@ import useAutoSave from "@/hooks/use-auto-save";
|
|||
|
||||
type TArgs = {
|
||||
editorRef: React.RefObject<EditorRefApi>;
|
||||
fetchPageDescription: () => Promise<any>;
|
||||
fetchPageDescription: () => Promise<ArrayBuffer>;
|
||||
hasConnectionFailed: boolean;
|
||||
updatePageDescription: (data: TDocumentPayload) => Promise<void>;
|
||||
};
|
||||
|
|
@ -21,10 +21,14 @@ export const usePageFallback = (args: TArgs) => {
|
|||
const editor = editorRef.current;
|
||||
if (!editor) return;
|
||||
|
||||
try {
|
||||
const latestEncodedDescription = await fetchPageDescription();
|
||||
const latestDecodedDescription = latestEncodedDescription
|
||||
? new Uint8Array(latestEncodedDescription)
|
||||
: new Uint8Array();
|
||||
let latestDecodedDescription: Uint8Array;
|
||||
if (latestEncodedDescription && latestEncodedDescription.byteLength > 0) {
|
||||
latestDecodedDescription = new Uint8Array(latestEncodedDescription);
|
||||
} else {
|
||||
latestDecodedDescription = getBinaryDataFromDocumentEditorHTMLString("<p></p>");
|
||||
}
|
||||
|
||||
editor.setProviderDocument(latestDecodedDescription);
|
||||
const { binary, html, json } = editor.getDocument();
|
||||
|
|
@ -36,13 +40,16 @@ export const usePageFallback = (args: TArgs) => {
|
|||
description_html: html,
|
||||
description: json,
|
||||
});
|
||||
}, [hasConnectionFailed]);
|
||||
} catch (error) {
|
||||
console.error("Error in updating description using fallback logic:", error);
|
||||
}
|
||||
}, [editorRef, fetchPageDescription, hasConnectionFailed, updatePageDescription]);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasConnectionFailed) {
|
||||
handleUpdateDescription();
|
||||
}
|
||||
}, [hasConnectionFailed]);
|
||||
}, [handleUpdateDescription, hasConnectionFailed]);
|
||||
|
||||
useAutoSave(handleUpdateDescription);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue