mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 08:58:58 +01:00
chore(react/type_widget): have book react to reloaded children
This commit is contained in:
parent
fa55c5720e
commit
db7cda3fe6
@ -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">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user