mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	chore(react/collections/board): attempt to reload events
This commit is contained in:
		
							parent
							
								
									ecf8c4ffbe
								
							
						
					
					
						commit
						6f2d51f3ff
					
				| @ -65,6 +65,7 @@ async function recursiveGroupBy(branches: FBranch[], byColumn: ColumnMap, groupB | ||||
|     for (const branch of branches) { | ||||
|         const note = await branch.getNote(); | ||||
|         if (!note) { | ||||
|             console.warn("Not note found"); | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -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, saveC | ||||
|     const [ 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, saveC | ||||
|             const 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"> | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran