mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
fix(views/board): column desynchronising due to API management
This commit is contained in:
parent
d2646e291d
commit
b3777e6900
@ -133,6 +133,29 @@ export default class BoardApi {
|
|||||||
await this.viewStorage.store(this.persistedData);
|
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>) {
|
static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) {
|
||||||
const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";
|
const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";
|
||||||
|
|
||||||
|
@ -107,10 +107,6 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateApi(newApi: BoardApi) {
|
|
||||||
this.api = newApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.cleanupColumnDropIndicators();
|
this.cleanupColumnDropIndicators();
|
||||||
this.context.draggedColumn = null;
|
this.context.draggedColumn = null;
|
||||||
|
@ -21,6 +21,7 @@ export class DifferentialBoardRenderer {
|
|||||||
private pendingUpdate = false;
|
private pendingUpdate = false;
|
||||||
private parentNote: FNote;
|
private parentNote: FNote;
|
||||||
private viewStorage: ViewModeStorage<BoardData>;
|
private viewStorage: ViewModeStorage<BoardData>;
|
||||||
|
private onRefreshApi: () => Promise<void>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
$container: JQuery<HTMLElement>,
|
$container: JQuery<HTMLElement>,
|
||||||
@ -28,7 +29,8 @@ export class DifferentialBoardRenderer {
|
|||||||
dragHandler: BoardDragHandler,
|
dragHandler: BoardDragHandler,
|
||||||
onCreateNewItem: (column: string) => void,
|
onCreateNewItem: (column: string) => void,
|
||||||
parentNote: FNote,
|
parentNote: FNote,
|
||||||
viewStorage: ViewModeStorage<BoardData>
|
viewStorage: ViewModeStorage<BoardData>,
|
||||||
|
onRefreshApi: () => Promise<void>
|
||||||
) {
|
) {
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
@ -36,13 +38,13 @@ export class DifferentialBoardRenderer {
|
|||||||
this.onCreateNewItem = onCreateNewItem;
|
this.onCreateNewItem = onCreateNewItem;
|
||||||
this.parentNote = parentNote;
|
this.parentNote = parentNote;
|
||||||
this.viewStorage = viewStorage;
|
this.viewStorage = viewStorage;
|
||||||
|
this.onRefreshApi = onRefreshApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderBoard(refreshApi = false): Promise<void> {
|
async renderBoard(refreshApi = false): Promise<void> {
|
||||||
// Refresh API data if requested
|
// Refresh API data if requested
|
||||||
if (refreshApi) {
|
if (refreshApi) {
|
||||||
this.api = await BoardApi.build(this.parentNote, this.viewStorage);
|
await this.onRefreshApi();
|
||||||
this.dragHandler.updateApi(this.api);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debounce rapid updates
|
// Debounce rapid updates
|
||||||
|
@ -35,12 +35,6 @@ export class BoardDragHandler {
|
|||||||
this.columnDragHandler.setupColumnDropZone($columnEl);
|
this.columnDragHandler.setupColumnDropZone($columnEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common methods
|
|
||||||
updateApi(newApi: BoardApi) {
|
|
||||||
this.noteDragHandler.updateApi(newApi);
|
|
||||||
this.columnDragHandler.updateApi(newApi);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.noteDragHandler.cleanup();
|
this.noteDragHandler.cleanup();
|
||||||
this.columnDragHandler.cleanup();
|
this.columnDragHandler.cleanup();
|
||||||
|
@ -8,5 +8,4 @@ export interface DragContext {
|
|||||||
|
|
||||||
export interface BaseDragHandler {
|
export interface BaseDragHandler {
|
||||||
cleanup(): void;
|
cleanup(): void;
|
||||||
updateApi(api: any): void;
|
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,8 @@ export default class BoardView extends ViewMode<BoardData> {
|
|||||||
this.dragHandler,
|
this.dragHandler,
|
||||||
(column: string) => this.createNewItem(column),
|
(column: string) => this.createNewItem(column),
|
||||||
this.parentNote,
|
this.parentNote,
|
||||||
this.viewStorage
|
this.viewStorage,
|
||||||
|
() => this.refreshApi()
|
||||||
);
|
);
|
||||||
|
|
||||||
setupContextMenu({
|
setupContextMenu({
|
||||||
@ -350,6 +351,14 @@ export default class BoardView extends ViewMode<BoardData> {
|
|||||||
this.setupBoardInteractions();
|
this.setupBoardInteractions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async refreshApi(): Promise<void> {
|
||||||
|
if (!this.api) {
|
||||||
|
throw new Error("API not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.api.refresh(this.parentNote);
|
||||||
|
}
|
||||||
|
|
||||||
private setupBoardInteractions() {
|
private setupBoardInteractions() {
|
||||||
// Handle column title editing with click detection that works with dragging
|
// Handle column title editing with click detection that works with dragging
|
||||||
this.$container.on('mousedown', 'h3[data-column-value]', (e) => {
|
this.$container.on('mousedown', 'h3[data-column-value]', (e) => {
|
||||||
|
@ -67,10 +67,6 @@ export class NoteDragHandler implements BaseDragHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateApi(newApi: BoardApi) {
|
|
||||||
this.api = newApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.cleanupAllDropIndicators();
|
this.cleanupAllDropIndicators();
|
||||||
this.$container.find('.board-column').removeClass('drag-over');
|
this.$container.find('.board-column').removeClass('drag-over');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user