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

This commit is contained in:
Elian Doran 2025-09-19 19:06:07 +03:00
parent fa55c5720e
commit db7cda3fe6
No known key found for this signature in database

View File

@ -1,15 +1,27 @@
import { t } from "../../services/i18n"; import { t } from "../../services/i18n";
import Alert from "../react/Alert"; import Alert from "../react/Alert";
import { useNoteLabel } from "../react/hooks"; import { useNoteLabel, useTriliumEvent } from "../react/hooks";
import RawHtml from "../react/RawHtml"; import RawHtml from "../react/RawHtml";
import { TypeWidgetProps } from "./type_widget"; import { TypeWidgetProps } from "./type_widget";
import "./Book.css"; import "./Book.css";
import { useEffect, useState } from "preact/hooks";
const VIEW_TYPES = [ "list", "grid" ]; const VIEW_TYPES = [ "list", "grid" ];
export default function Book({ note }: TypeWidgetProps) { export default function Book({ note }: TypeWidgetProps) {
const [ viewType ] = useNoteLabel(note, "viewType"); 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 ( return (
<div className="note-detail-book note-detail-printable"> <div className="note-detail-book note-detail-printable">