mirror of
https://github.com/zadam/trilium.git
synced 2025-11-30 04:24:24 +01:00
fix(type_widgets): empty type widget when hot-reloading NoteDetail
This commit is contained in:
parent
80627997d1
commit
1fe8079fd5
@ -28,7 +28,7 @@ export default function NoteDetail() {
|
|||||||
const { note, type, mime, noteContext, parentComponent } = useNoteInfo();
|
const { note, type, mime, noteContext, parentComponent } = useNoteInfo();
|
||||||
const { ntxId, viewScope } = noteContext ?? {};
|
const { ntxId, viewScope } = noteContext ?? {};
|
||||||
const isFullHeight = checkFullHeight(noteContext, type);
|
const isFullHeight = checkFullHeight(noteContext, type);
|
||||||
const noteTypesToRender = useRef<{ [ key in ExtendedNoteType ]?: (props: TypeWidgetProps) => VNode }>({});
|
const [ noteTypesToRender, setNoteTypesToRender ] = useState<{ [ key in ExtendedNoteType ]?: (props: TypeWidgetProps) => VNode }>({});
|
||||||
const [ activeNoteType, setActiveNoteType ] = useState<ExtendedNoteType>();
|
const [ activeNoteType, setActiveNoteType ] = useState<ExtendedNoteType>();
|
||||||
|
|
||||||
const props: TypeWidgetProps = {
|
const props: TypeWidgetProps = {
|
||||||
@ -38,19 +38,23 @@ export default function NoteDetail() {
|
|||||||
parentComponent,
|
parentComponent,
|
||||||
noteContext
|
noteContext
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!type) return;
|
if (!type) return;
|
||||||
|
|
||||||
if (!noteTypesToRender.current[type]) {
|
if (!noteTypesToRender[type]) {
|
||||||
getCorrespondingWidget(type).then((el) => {
|
getCorrespondingWidget(type).then((el) => {
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
noteTypesToRender.current[type] = el;
|
setNoteTypesToRender(prev => ({
|
||||||
|
...prev,
|
||||||
|
[type]: el
|
||||||
|
}));
|
||||||
setActiveNoteType(type);
|
setActiveNoteType(type);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setActiveNoteType(type);
|
setActiveNoteType(type);
|
||||||
}
|
}
|
||||||
}, [ note, viewScope, type ]);
|
}, [ note, viewScope, type, noteTypesToRender ]);
|
||||||
|
|
||||||
// Detect note type changes.
|
// Detect note type changes.
|
||||||
useTriliumEvent("entitiesReloaded", async ({ loadResults }) => {
|
useTriliumEvent("entitiesReloaded", async ({ loadResults }) => {
|
||||||
@ -192,7 +196,7 @@ export default function NoteDetail() {
|
|||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
class={`note-detail ${isFullHeight ? "full-height" : ""}`}
|
class={`note-detail ${isFullHeight ? "full-height" : ""}`}
|
||||||
>
|
>
|
||||||
{Object.entries(noteTypesToRender.current).map(([ itemType, Element ]) => {
|
{Object.entries(noteTypesToRender).map(([ itemType, Element ]) => {
|
||||||
return <NoteDetailWrapper
|
return <NoteDetailWrapper
|
||||||
Element={Element}
|
Element={Element}
|
||||||
key={itemType}
|
key={itemType}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user