Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): have book react to reloaded children

Elian Dorandb7cda3fe633
diff --git a/apps/client/src/widgets/type_widgets/Book.tsx b/apps/client/src/widgets/type_widgets/Book.tsx
index a591626ab3..b27dd63d29 100644
--- a/apps/client/src/widgets/type_widgets/Book.tsx
+++ b/apps/client/src/widgets/type_widgets/Book.tsx
@@ -1,15 +1,27 @@
import { t } from "../../services/i18n";
import Alert from "../react/Alert";
-import { useNoteLabel } from "../react/hooks";
+import { useNoteLabel, useTriliumEvent } from "../react/hooks";
import RawHtml from "../react/RawHtml";
import { TypeWidgetProps } from "./type_widget";
import "./Book.css";
+import { useEffect, useState } from "preact/hooks";
const VIEW_TYPES = [ "list", "grid" ];
export default function Book({ note }: TypeWidgetProps) {
const [ viewType ] = useNoteLabel(note, "viewType");
- const shouldDisplayNoChildrenWarning = !note.hasChildren() && VIEW_TYPES.includes(viewType ?? "");
+ const [ shouldDisplayNoChildrenWarning, setShouldDisplayNoChildrenWarning ] = useState(false);
+
+ function refresh() {
+ setShouldDisplayNoChildrenWarning(!note.hasChildren() && VIEW_TYPES.includes(viewType ?? ""));
+ }
+
+ useEffect(refresh, [ note ]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (loadResults.getBranchRows().some(branchRow => branchRow.parentNoteId === note.noteId)) {
+ refresh();
+ }
+ });
return (
<div className="note-detail-book note-detail-printable">