chore(react/type_widget): reload content on external change

This commit is contained in:
Elian Doran
2025-09-20 09:56:55 +03:00
parent 63e3a27b34
commit 79be13e6c7

View File

@@ -82,7 +82,7 @@ export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSave
dataSaved?: () => void
}) {
const parentComponent = useContext(ParentComponent);
const blob = useNoteBlob(note);
const blob = useNoteBlob(note, parentComponent?.componentId);
const callback = useMemo(() => {
return async () => {
@@ -99,6 +99,7 @@ export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSave
}, [ note, getData, dataSaved ])
const spacedUpdate = useSpacedUpdate(callback);
// React to note/blob changes.
useEffect(() => {
if (!blob) return;
spacedUpdate.allowUpdateWithoutChange(() => onContentChange(blob.content));
@@ -402,7 +403,7 @@ export function useNoteLabelInt(note: FNote | undefined | null, labelName: Filte
]
}
export function useNoteBlob(note: FNote | null | undefined): FBlob | null | undefined {
export function useNoteBlob(note: FNote | null | undefined, componentId?: string): FBlob | null | undefined {
const [ blob, setBlob ] = useState<FBlob | null>();
function refresh() {
@@ -423,6 +424,10 @@ export function useNoteBlob(note: FNote | null | undefined): FBlob | null | unde
if (loadResults.hasRevisionForNote(note.noteId)) {
refresh();
}
if (loadResults.isNoteContentReloaded(note.noteId, componentId)) {
refresh();
}
});
useDebugValue(note?.noteId);