diff --git a/apps/client/src/widgets/type_widgets/Book.tsx b/apps/client/src/widgets/type_widgets/Book.tsx index a591626ab..b27dd63d2 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 (