Skip to content

Build your personal knowledge base with Trilium Notes

fix(views/board): column desynchronising due to API management

Elian Doranb3777e6900ee
diff --git a/apps/client/src/widgets/view_widgets/board_view/api.ts b/apps/client/src/widgets/view_widgets/board_view/api.ts
index 4b6f55e3c2..38846d2db2 100644
--- a/apps/client/src/widgets/view_widgets/board_view/api.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/api.ts
@@ -133,6 +133,29 @@ export default class BoardApi {
await this.viewStorage.store(this.persistedData);
}
+ async refresh(parentNote: FNote) {
+ // Refresh the API data by re-fetching from the parent note
+ const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";
+ this._statusAttribute = statusAttribute;
+
+ let persistedData = await this.viewStorage.restore() ?? {};
+ const { byColumn, newPersistedData } = await getBoardData(parentNote, statusAttribute, persistedData);
+
+ // Update internal state
+ this.byColumn = byColumn;
+
+ if (newPersistedData) {
+ this.persistedData = newPersistedData;
+ this.viewStorage.store(this.persistedData);
+ }
+
+ // Use the order from persistedData.columns, then add any new columns found
+ const orderedColumns = this.persistedData.columns?.map(col => col.value) || [];
+ const allColumns = Array.from(byColumn.keys());
+ const newColumns = allColumns.filter(col => !orderedColumns.includes(col));
+ this._columns = [...orderedColumns, ...newColumns];
+ }
+
static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) {
const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";
diff --git a/apps/client/src/widgets/view_widgets/board_view/column_drag_handler.ts b/apps/client/src/widgets/view_widgets/board_view/column_drag_handler.ts
index 32e6349e9e..cfb22901ad 100644
--- a/apps/client/src/widgets/view_widgets/board_view/column_drag_handler.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/column_drag_handler.ts
@@ -107,10 +107,6 @@ export class ColumnDragHandler implements BaseDragHandler {
});
}
- updateApi(newApi: BoardApi) {
- this.api = newApi;
- }
-
cleanup() {
this.cleanupColumnDropIndicators();
this.context.draggedColumn = null;
diff --git a/apps/client/src/widgets/view_widgets/board_view/differential_renderer.ts b/apps/client/src/widgets/view_widgets/board_view/differential_renderer.ts
index 793ef4c2ef..4f1cf64dc8 100644
--- a/apps/client/src/widgets/view_widgets/board_view/differential_renderer.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/differential_renderer.ts
@@ -21,6 +21,7 @@ export class DifferentialBoardRenderer {
private pendingUpdate = false;
private parentNote: FNote;
private viewStorage: ViewModeStorage<BoardData>;
+ private onRefreshApi: () => Promise<void>;
constructor(
$container: JQuery<HTMLElement>,
@@ -28,7 +29,8 @@ export class DifferentialBoardRenderer {
dragHandler: BoardDragHandler,
onCreateNewItem: (column: string) => void,
parentNote: FNote,
- viewStorage: ViewModeStorage<BoardData>
+ viewStorage: ViewModeStorage<BoardData>,
+ onRefreshApi: () => Promise<void>
) {
this.$container = $container;
this.api = api;
@@ -36,13 +38,13 @@ export class DifferentialBoardRenderer {
this.onCreateNewItem = onCreateNewItem;
this.parentNote = parentNote;
this.viewStorage = viewStorage;
+ this.onRefreshApi = onRefreshApi;
}
async renderBoard(refreshApi = false): Promise<void> {
// Refresh API data if requested
if (refreshApi) {
- this.api = await BoardApi.build(this.parentNote, this.viewStorage);
- this.dragHandler.updateApi(this.api);
+ await this.onRefreshApi();
}
// Debounce rapid updates
diff --git a/apps/client/src/widgets/view_widgets/board_view/drag_handler.ts b/apps/client/src/widgets/view_widgets/board_view/drag_handler.ts
index d29ff8d67f..11be8f9f23 100644
--- a/apps/client/src/widgets/view_widgets/board_view/drag_handler.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/drag_handler.ts
@@ -35,12 +35,6 @@ export class BoardDragHandler {
this.columnDragHandler.setupColumnDropZone($columnEl);
}
- // Common methods
- updateApi(newApi: BoardApi) {
- this.noteDragHandler.updateApi(newApi);
- this.columnDragHandler.updateApi(newApi);
- }
-
cleanup() {
this.noteDragHandler.cleanup();
this.columnDragHandler.cleanup();
diff --git a/apps/client/src/widgets/view_widgets/board_view/drag_types.ts b/apps/client/src/widgets/view_widgets/board_view/drag_types.ts
index ff3cde8c76..3957ee2e90 100644
--- a/apps/client/src/widgets/view_widgets/board_view/drag_types.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/drag_types.ts
@@ -8,5 +8,4 @@ export interface DragContext {
export interface BaseDragHandler {
cleanup(): void;
- updateApi(api: any): void;
}
diff --git a/apps/client/src/widgets/view_widgets/board_view/index.ts b/apps/client/src/widgets/view_widgets/board_view/index.ts
index 2dad75e521..c2a628a95b 100644
--- a/apps/client/src/widgets/view_widgets/board_view/index.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/index.ts
@@ -337,7 +337,8 @@ export default class BoardView extends ViewMode<BoardData> {
this.dragHandler,
(column: string) => this.createNewItem(column),
this.parentNote,
- this.viewStorage
+ this.viewStorage,
+ () => this.refreshApi()
);
setupContextMenu({
@@ -350,6 +351,14 @@ export default class BoardView extends ViewMode<BoardData> {
this.setupBoardInteractions();
}
+ private async refreshApi(): Promise<void> {
+ if (!this.api) {
+ throw new Error("API not initialized");
+ }
+
+ await this.api.refresh(this.parentNote);
+ }
+
private setupBoardInteractions() {
// Handle column title editing with click detection that works with dragging
this.$container.on('mousedown', 'h3[data-column-value]', (e) => {
diff --git a/apps/client/src/widgets/view_widgets/board_view/note_drag_handler.ts b/apps/client/src/widgets/view_widgets/board_view/note_drag_handler.ts
index 6be711846f..ef08d79004 100644
--- a/apps/client/src/widgets/view_widgets/board_view/note_drag_handler.ts
+++ b/apps/client/src/widgets/view_widgets/board_view/note_drag_handler.ts
@@ -67,10 +67,6 @@ export class NoteDragHandler implements BaseDragHandler {
});
}
- updateApi(newApi: BoardApi) {
- this.api = newApi;
- }
-
cleanup() {
this.cleanupAllDropIndicators();
this.$container.find('.board-column').removeClass('drag-over');