refactor(react/type_widget): simplify handling of new notes

This commit is contained in:
Elian Doran
2025-09-20 09:47:28 +03:00
parent 9eae6620d0
commit 63e3a27b34
2 changed files with 15 additions and 10 deletions

View File

@@ -75,12 +75,15 @@ export function useSpacedUpdate(callback: () => void | Promise<void>, interval =
return spacedUpdateRef.current;
}
export function useEditorSpacedUpdate({ note, getData, dataSaved }: {
export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSaved }: {
note: FNote,
getData: () => Promise<object | undefined> | object | undefined,
onContentChange: (newContent: string) => void,
dataSaved?: () => void
}) {
const parentComponent = useContext(ParentComponent);
const blob = useNoteBlob(note);
const callback = useMemo(() => {
return async () => {
const data = await getData();
@@ -95,6 +98,12 @@ export function useEditorSpacedUpdate({ note, getData, dataSaved }: {
}
}, [ note, getData, dataSaved ])
const spacedUpdate = useSpacedUpdate(callback);
useEffect(() => {
if (!blob) return;
spacedUpdate.allowUpdateWithoutChange(() => onContentChange(blob.content));
}, [ blob ]);
return spacedUpdate;
}