mirror of
https://github.com/makeplane/plane.git
synced 2026-07-12 21:40:18 +02:00
* chore: new description binary endpoints * chore: conflict free issue description * chore: fix submitting status * chore: update yjs utils * chore: handle component re-mounting * chore: update buffer response type * chore: add try catch for issue description update * chore: update buffer response type * chore: description binary in retrieve * chore: update issue description hook * chore: decode description binary * chore: migrations fixes and cleanup * chore: migration fixes * fix: inbox issue description * chore: move update operations to the issue store * fix: merge conflicts * chore: reverted the commit * chore: removed the unwanted imports * chore: remove unnecessary props * chore: remove unused services * chore: update live server error handling --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { useCallback, useEffect, useState } from "react";
|
|
// plane editor
|
|
import {
|
|
convertBase64StringToBinaryData,
|
|
EditorRefApi,
|
|
getBinaryDataFromRichTextEditorHTMLString,
|
|
} from "@plane/editor";
|
|
|
|
type TArgs = {
|
|
descriptionBinary: string | null;
|
|
descriptionHTML: string | null;
|
|
updateDescription?: (data: string) => Promise<ArrayBuffer>;
|
|
};
|
|
|
|
export const useIssueDescription = (args: TArgs) => {
|
|
const { descriptionBinary: savedDescriptionBinary, descriptionHTML, updateDescription } = args;
|
|
// states
|
|
const [descriptionBinary, setDescriptionBinary] = useState<Uint8Array | null>(null);
|
|
// update description
|
|
const resolveConflictsAndUpdateDescription = useCallback(
|
|
async (encodedDescription: string, editorRef: EditorRefApi | null) => {
|
|
if (!updateDescription) return;
|
|
try {
|
|
const conflictFreeEncodedDescription = await updateDescription(encodedDescription);
|
|
const decodedDescription = conflictFreeEncodedDescription
|
|
? new Uint8Array(conflictFreeEncodedDescription)
|
|
: new Uint8Array();
|
|
editorRef?.setProviderDocument(decodedDescription);
|
|
} catch (error) {
|
|
console.error("Error while updating description", error);
|
|
}
|
|
},
|
|
[updateDescription]
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (descriptionBinary) return;
|
|
if (savedDescriptionBinary) {
|
|
const savedDescriptionBuffer = convertBase64StringToBinaryData(savedDescriptionBinary);
|
|
const decodedSavedDescription = savedDescriptionBuffer
|
|
? new Uint8Array(savedDescriptionBuffer)
|
|
: new Uint8Array();
|
|
setDescriptionBinary(decodedSavedDescription);
|
|
} else {
|
|
const decodedDescriptionHTML = getBinaryDataFromRichTextEditorHTMLString(descriptionHTML ?? "<p></p>");
|
|
setDescriptionBinary(decodedDescriptionHTML);
|
|
}
|
|
}, [descriptionBinary, descriptionHTML, savedDescriptionBinary]);
|
|
|
|
return {
|
|
descriptionBinary,
|
|
resolveConflictsAndUpdateDescription,
|
|
};
|
|
};
|