Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react/collections/board): attempt to reload events
Elian Doran6f2d51f3ffc2
diff --git a/apps/client/src/widgets/collections/board/data.ts b/apps/client/src/widgets/collections/board/data.tsindex 2a59e82b78..47cc101449 100644--- a/apps/client/src/widgets/collections/board/data.ts+++ b/apps/client/src/widgets/collections/board/data.ts@@ -65,6 +65,7 @@ async function recursiveGroupBy(branches: FBranch[], byColumn: ColumnMap, groupBfor (const branch of branches) {const note = await branch.getNote();if (!note) {+ console.warn("Not note found");continue;}diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex d47a066bc1..97cdbf97a3 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -2,7 +2,7 @@ import { useEffect, useState } from "preact/hooks";import { ViewModeProps } from "../interface";import "./index.css";import { ColumnMap, getBoardData } from "./data";-import { useNoteLabel } from "../../react/hooks";+import { useNoteLabel, useTriliumEvent } from "../../react/hooks";import FNote from "../../../entities/fnote";import FBranch from "../../../entities/fbranch";import Icon from "../../react/Icon";@@ -22,7 +22,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveCconst [ byColumn, setByColumn ] = useState<ColumnMap>();const [ columns, setColumns ] = useState<string[]>();- useEffect(() => {+ function refresh() {getBoardData(parentNote, statusAttribute ?? "status", viewConfig ?? {}).then(({ byColumn, newPersistedData }) => {setByColumn(byColumn);@@ -37,7 +37,34 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveCconst newColumns = allColumns.filter(col => !orderedColumns.includes(col));setColumns([...orderedColumns, ...newColumns]);});- }, [ parentNote ]);+ }++ useEffect(refresh, [ parentNote, noteIds ]);++ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ // TODO: Re-enable+ return;++ // Check if any changes affect our board+ const hasRelevantChanges =+ // React to changes in status attribute for notes in this board+ loadResults.getAttributeRows().some(attr => attr.name === statusAttribute && noteIds.includes(attr.noteId!)) ||+ // React to changes in note title+ loadResults.getNoteIds().some(noteId => noteIds.includes(noteId)) ||+ // React to changes in branches for subchildren (e.g., moved, added, or removed notes)+ loadResults.getBranchRows().some(branch => noteIds.includes(branch.noteId!)) ||+ // React to changes in note icon or color.+ loadResults.getAttributeRows().some(attr => [ "iconClass", "color" ].includes(attr.name ?? "") && noteIds.includes(attr.noteId ?? "")) ||+ // React to attachment change+ loadResults.getAttachmentRows().some(att => att.ownerId === parentNote.noteId && att.title === "board.json") ||+ // React to changes in "groupBy"+ loadResults.getAttributeRows().some(attr => attr.name === "board:groupBy" && attr.noteId === parentNote.noteId);++ if (hasRelevantChanges) {+ console.log("Trigger refresh");+ refresh();+ }+ });return (<div className="board-view">diff --git a/apps/client/src/widgets/view_widgets/board_view/index.ts b/apps/client/src/widgets/view_widgets/board_view/index.tsindex 489fd0b958..5b874a5f7e 100644--- a/apps/client/src/widgets/view_widgets/board_view/index.ts+++ b/apps/client/src/widgets/view_widgets/board_view/index.ts@@ -318,31 +318,6 @@ export default class BoardView extends ViewMode<BoardData> {}}- async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {- // Check if any changes affect our board- const hasRelevantChanges =- // React to changes in status attribute for notes in this board- loadResults.getAttributeRows().some(attr => attr.name === this.api?.statusAttribute && this.noteIds.includes(attr.noteId!)) ||- // React to changes in note title- loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)) ||- // React to changes in branches for subchildren (e.g., moved, added, or removed notes)- loadResults.getBranchRows().some(branch => this.noteIds.includes(branch.noteId!)) ||- // React to changes in note icon or color.- loadResults.getAttributeRows().some(attr => [ "iconClass", "color" ].includes(attr.name ?? "") && this.noteIds.includes(attr.noteId ?? "")) ||- // React to attachment change- loadResults.getAttachmentRows().some(att => att.ownerId === this.parentNote.noteId && att.title === "board.json") ||- // React to changes in "groupBy"- loadResults.getAttributeRows().some(attr => attr.name === "board:groupBy" && attr.noteId === this.parentNote.noteId);-- if (hasRelevantChanges && this.renderer) {- // Use differential rendering with API refresh- await this.renderer.renderBoard(true);- }-- // Don't trigger full view refresh - let differential renderer handle it- return false;- }-private onSave() {this.viewStorage.store(this.persistentData);}