mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 20:49:01 +01:00
refactor(views/board): unnecessary API to manually refresh the board
This commit is contained in:
parent
d9820d9725
commit
62de52ab17
@ -5,23 +5,20 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
private $container: JQuery<HTMLElement>;
|
private $container: JQuery<HTMLElement>;
|
||||||
private api: BoardApi;
|
private api: BoardApi;
|
||||||
private context: DragContext;
|
private context: DragContext;
|
||||||
private onBoardRefresh: () => Promise<void>;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
$container: JQuery<HTMLElement>,
|
$container: JQuery<HTMLElement>,
|
||||||
api: BoardApi,
|
api: BoardApi,
|
||||||
context: DragContext,
|
context: DragContext,
|
||||||
onBoardRefresh: () => Promise<void>
|
|
||||||
) {
|
) {
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.onBoardRefresh = onBoardRefresh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setupColumnDrag($columnEl: JQuery<HTMLElement>, columnValue: string) {
|
setupColumnDrag($columnEl: JQuery<HTMLElement>, columnValue: string) {
|
||||||
const $titleEl = $columnEl.find('h3[data-column-value]');
|
const $titleEl = $columnEl.find('h3[data-column-value]');
|
||||||
|
|
||||||
$titleEl.attr("draggable", "true");
|
$titleEl.attr("draggable", "true");
|
||||||
|
|
||||||
// Delay drag start to allow click detection
|
// Delay drag start to allow click detection
|
||||||
@ -79,7 +76,7 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
this.context.draggedColumnElement = null;
|
this.context.draggedColumnElement = null;
|
||||||
this.cleanupColumnDropIndicators();
|
this.cleanupColumnDropIndicators();
|
||||||
this.cleanupGlobalColumnDragTracking();
|
this.cleanupGlobalColumnDragTracking();
|
||||||
|
|
||||||
// Re-enable draggable
|
// Re-enable draggable
|
||||||
$titleEl.attr("draggable", "true");
|
$titleEl.attr("draggable", "true");
|
||||||
});
|
});
|
||||||
@ -160,7 +157,7 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
if (this.context.draggedColumnElement) {
|
if (this.context.draggedColumnElement) {
|
||||||
$allColumns = $allColumns.not(this.context.draggedColumnElement);
|
$allColumns = $allColumns.not(this.context.draggedColumnElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
let $targetColumn: JQuery<HTMLElement> = $();
|
let $targetColumn: JQuery<HTMLElement> = $();
|
||||||
let insertBefore = false;
|
let insertBefore = false;
|
||||||
|
|
||||||
@ -197,7 +194,7 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
|
|
||||||
if ($targetColumn.length > 0) {
|
if ($targetColumn.length > 0) {
|
||||||
const $dropIndicator = $("<div>").addClass("column-drop-indicator");
|
const $dropIndicator = $("<div>").addClass("column-drop-indicator");
|
||||||
|
|
||||||
if (insertBefore) {
|
if (insertBefore) {
|
||||||
$targetColumn.before($dropIndicator);
|
$targetColumn.before($dropIndicator);
|
||||||
} else {
|
} else {
|
||||||
@ -210,7 +207,7 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
|
|
||||||
private async handleColumnDrop() {
|
private async handleColumnDrop() {
|
||||||
console.log("handleColumnDrop called for:", this.context.draggedColumn);
|
console.log("handleColumnDrop called for:", this.context.draggedColumn);
|
||||||
|
|
||||||
if (!this.context.draggedColumn || !this.context.draggedColumnElement) {
|
if (!this.context.draggedColumn || !this.context.draggedColumnElement) {
|
||||||
console.log("No dragged column or element found");
|
console.log("No dragged column or element found");
|
||||||
return;
|
return;
|
||||||
@ -220,22 +217,22 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
// Find the drop indicator to determine insert position
|
// Find the drop indicator to determine insert position
|
||||||
const $dropIndicator = this.$container.find(".column-drop-indicator.show");
|
const $dropIndicator = this.$container.find(".column-drop-indicator.show");
|
||||||
console.log("Drop indicator found:", $dropIndicator.length > 0);
|
console.log("Drop indicator found:", $dropIndicator.length > 0);
|
||||||
|
|
||||||
if ($dropIndicator.length > 0) {
|
if ($dropIndicator.length > 0) {
|
||||||
// Get current column order from the API (source of truth)
|
// Get current column order from the API (source of truth)
|
||||||
const currentOrder = [...this.api.columns];
|
const currentOrder = [...this.api.columns];
|
||||||
|
|
||||||
let newOrder = [...currentOrder];
|
let newOrder = [...currentOrder];
|
||||||
|
|
||||||
// Remove dragged column from current position
|
// Remove dragged column from current position
|
||||||
newOrder = newOrder.filter(col => col !== this.context.draggedColumn);
|
newOrder = newOrder.filter(col => col !== this.context.draggedColumn);
|
||||||
|
|
||||||
// Determine insertion position based on drop indicator position
|
// Determine insertion position based on drop indicator position
|
||||||
const $nextColumn = $dropIndicator.next('.board-column');
|
const $nextColumn = $dropIndicator.next('.board-column');
|
||||||
const $prevColumn = $dropIndicator.prev('.board-column');
|
const $prevColumn = $dropIndicator.prev('.board-column');
|
||||||
|
|
||||||
let insertIndex = -1;
|
let insertIndex = -1;
|
||||||
|
|
||||||
if ($nextColumn.length > 0) {
|
if ($nextColumn.length > 0) {
|
||||||
// Insert before the next column
|
// Insert before the next column
|
||||||
const nextColumnValue = $nextColumn.attr('data-column');
|
const nextColumnValue = $nextColumn.attr('data-column');
|
||||||
@ -263,9 +260,6 @@ export class ColumnDragHandler implements BaseDragHandler {
|
|||||||
|
|
||||||
// Update column order in API
|
// Update column order in API
|
||||||
await this.api.reorderColumns(newOrder);
|
await this.api.reorderColumns(newOrder);
|
||||||
|
|
||||||
// Refresh the board to reflect the changes
|
|
||||||
await this.onBoardRefresh();
|
|
||||||
} else {
|
} else {
|
||||||
console.warn("No drop indicator found for column drop");
|
console.warn("No drop indicator found for column drop");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,7 @@ export class BoardDragHandler {
|
|||||||
private $container: JQuery<HTMLElement>;
|
private $container: JQuery<HTMLElement>;
|
||||||
private api: BoardApi;
|
private api: BoardApi;
|
||||||
private context: DragContext;
|
private context: DragContext;
|
||||||
private onBoardRefresh: () => Promise<void>;
|
|
||||||
|
|
||||||
private noteDragHandler: NoteDragHandler;
|
private noteDragHandler: NoteDragHandler;
|
||||||
private columnDragHandler: ColumnDragHandler;
|
private columnDragHandler: ColumnDragHandler;
|
||||||
|
|
||||||
@ -16,16 +15,14 @@ export class BoardDragHandler {
|
|||||||
$container: JQuery<HTMLElement>,
|
$container: JQuery<HTMLElement>,
|
||||||
api: BoardApi,
|
api: BoardApi,
|
||||||
context: DragContext,
|
context: DragContext,
|
||||||
onBoardRefresh: () => Promise<void>
|
|
||||||
) {
|
) {
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.onBoardRefresh = onBoardRefresh;
|
|
||||||
|
|
||||||
// Initialize specialized drag handlers
|
// Initialize specialized drag handlers
|
||||||
this.noteDragHandler = new NoteDragHandler($container, api, context, onBoardRefresh);
|
this.noteDragHandler = new NoteDragHandler($container, api, context);
|
||||||
this.columnDragHandler = new ColumnDragHandler($container, api, context, onBoardRefresh);
|
this.columnDragHandler = new ColumnDragHandler($container, api, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note drag methods - delegate to NoteDragHandler
|
// Note drag methods - delegate to NoteDragHandler
|
||||||
|
|||||||
@ -334,8 +334,7 @@ export default class BoardView extends ViewMode<BoardData> {
|
|||||||
this.dragHandler = new BoardDragHandler(
|
this.dragHandler = new BoardDragHandler(
|
||||||
this.$container,
|
this.$container,
|
||||||
this.api,
|
this.api,
|
||||||
this.dragContext,
|
this.dragContext
|
||||||
async () => { await this.renderList(); }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.renderer = new DifferentialBoardRenderer(
|
this.renderer = new DifferentialBoardRenderer(
|
||||||
|
|||||||
@ -6,18 +6,15 @@ export class NoteDragHandler implements BaseDragHandler {
|
|||||||
private $container: JQuery<HTMLElement>;
|
private $container: JQuery<HTMLElement>;
|
||||||
private api: BoardApi;
|
private api: BoardApi;
|
||||||
private context: DragContext;
|
private context: DragContext;
|
||||||
private onBoardRefresh: () => Promise<void>;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
$container: JQuery<HTMLElement>,
|
$container: JQuery<HTMLElement>,
|
||||||
api: BoardApi,
|
api: BoardApi,
|
||||||
context: DragContext,
|
context: DragContext,
|
||||||
onBoardRefresh: () => Promise<void>
|
|
||||||
) {
|
) {
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.onBoardRefresh = onBoardRefresh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setupNoteDrag($noteEl: JQuery<HTMLElement>, note: any, branch: any) {
|
setupNoteDrag($noteEl: JQuery<HTMLElement>, note: any, branch: any) {
|
||||||
@ -308,9 +305,6 @@ export class NoteDragHandler implements BaseDragHandler {
|
|||||||
|
|
||||||
// Update the data attributes
|
// Update the data attributes
|
||||||
draggedNoteElement.attr("data-current-column", column);
|
draggedNoteElement.attr("data-current-column", column);
|
||||||
|
|
||||||
// Refresh the board to reflect the changes
|
|
||||||
await this.onBoardRefresh();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update note position:", error);
|
console.error("Failed to update note position:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user