feat(react): set up hook for reacting to events

This commit is contained in:
Elian Doran
2025-08-08 20:08:06 +03:00
parent bd6c690160
commit 3975041798
4 changed files with 58 additions and 24 deletions

View File

@@ -15,6 +15,7 @@ import RenameNoteBulkAction from "../bulk_actions/note/rename_note";
import { RawHtmlBlock } from "../react/RawHtml";
import FNote from "../../entities/fnote";
import froca from "../../services/froca";
import useTriliumEvent from "../react/hooks";
interface BulkActionProps {
bulkActionNote?: FNote | null;
@@ -42,6 +43,10 @@ function BulkActionComponent({ selectedOrActiveNoteIds, bulkActionNote }: BulkAc
setExistingActions(bulk_action.parseActions(bulkActionNote));
}, []);
useTriliumEvent("entitiesReloaded", () => {
console.log("Got entities reloaded.");
});
return ( selectedOrActiveNoteIds &&
<Modal
className="bulk-actions-dialog"
@@ -130,14 +135,4 @@ export default class BulkActionsDialog extends ReactBasicWidget {
openDialog(this.$widget);
}
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
// only refreshing deleted attrs, otherwise components update themselves
if (loadResults.getAttributeRows().find((row) => row.type === "label" && row.name === "action" && row.noteId === "_bulkAction" && row.isDeleted)) {
// this may be triggered from e.g., sync without open widget, then no need to refresh the widget
if (this.props.selectedOrActiveNoteIds && this.$widget.is(":visible")) {
this.doRender();
}
}
}
}