Skip to content

Build your personal knowledge base with Trilium Notes

feat(tasks): support entities reloaded properly

Elian Doran034b93c99c29
diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts
index 16d81d3dfd..82970907b1 100644
--- a/src/becca/becca-interface.ts
+++ b/src/becca/becca-interface.ts
@@ -222,6 +222,10 @@ export default class Becca {
.filter((task) => !task.isDone);
}
+ getTask(taskId: string): BTask | null {
+ return this.tasks[taskId];
+ }
+
getEntity<T extends AbstractBeccaEntity<T>>(entityName: string, entityId: string): AbstractBeccaEntity<T> | null {
if (!entityName || !entityId) {
return null;
diff --git a/src/public/app/services/froca_updater.ts b/src/public/app/services/froca_updater.ts
index 617c4c277f..cf9dbbad04 100644
--- a/src/public/app/services/froca_updater.ts
+++ b/src/public/app/services/froca_updater.ts
@@ -335,6 +335,8 @@ function processTaskChange(loadResults: LoadResults, ec: EntityChange) {
froca.tasks[task.taskId] = task;
}
}
+
+ loadResults.addTaskRow(taskEntity);
}
export default {
diff --git a/src/public/app/services/load_results.ts b/src/public/app/services/load_results.ts
index 5ebfc7be5f..e91dfde86c 100644
--- a/src/public/app/services/load_results.ts
+++ b/src/public/app/services/load_results.ts
@@ -1,3 +1,4 @@
+import type { TaskRow } from "../../../becca/entities/rows.js";
import type { AttributeType } from "../entities/fattribute.js";
import type { EntityChange } from "../server_types.js";
@@ -69,6 +70,7 @@ export default class LoadResults {
private contentNoteIdToComponentId: ContentNoteIdToComponentIdRow[];
private optionNames: string[];
private attachmentRows: AttachmentRow[];
+ private taskRows: TaskRow[];
constructor(entityChanges: EntityChange[]) {
const entities: Record<string, Record<string, any>> = {};
@@ -97,6 +99,8 @@ export default class LoadResults {
this.optionNames = [];
this.attachmentRows = [];
+
+ this.taskRows = [];
}
getEntityRow<T extends EntityRowNames>(entityName: T, entityId: string): EntityRowMappings[T] {
@@ -199,6 +203,14 @@ export default class LoadResults {
return this.attachmentRows;
}
+ addTaskRow(task: TaskRow) {
+ this.taskRows.push(task);
+ }
+
+ getTaskRows() {
+ return this.taskRows;
+ }
+
/**
* @returns {boolean} true if there are changes which could affect the attributes (including inherited ones)
* notably changes in note itself should not have any effect on attributes
@@ -216,7 +228,8 @@ export default class LoadResults {
this.revisionRows.length === 0 &&
this.contentNoteIdToComponentId.length === 0 &&
this.optionNames.length === 0 &&
- this.attachmentRows.length === 0
+ this.attachmentRows.length === 0 &&
+ this.taskRows.length === 0
);
}
diff --git a/src/public/app/widgets/type_widgets/task_list.ts b/src/public/app/widgets/type_widgets/task_list.ts
index 861ebe634b..b54ee35c70 100644
--- a/src/public/app/widgets/type_widgets/task_list.ts
+++ b/src/public/app/widgets/type_widgets/task_list.ts
@@ -3,6 +3,7 @@ import type FTask from "../../entities/ftask.js";
import froca from "../../services/froca.js";
import TypeWidget from "./type_widget.js";
import * as taskService from "../../services/tasks.js";
+import type { EventData } from "../../components/app_context.js";
const TPL = `
<div class="note-detail-task-list note-detail-printable">
@@ -116,4 +117,8 @@ export default class TaskListWidget extends TypeWidget {
}
}
+ entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
+ console.log("Update", loadResults);
+ }
+
}
diff --git a/src/services/ws.ts b/src/services/ws.ts
index e163e25d72..f46a9b3f7d 100644
--- a/src/services/ws.ts
+++ b/src/services/ws.ts
@@ -188,6 +188,12 @@ function fillInAdditionalProperties(entityChange: EntityChange) {
WHERE attachmentId = ?`,
[entityChange.entityId]
);
+ } else if (entityChange.entityName === "tasks") {
+ entityChange.entity = becca.getTask(entityChange.entity);
+
+ if (!entityChange.entity) {
+ entityChange.entity = sql.getRow(`SELECT * FROM tasks WHERE taskId = ?`, [entityChange.entityId]);
+ }
}
if (entityChange.entity instanceof AbstractBeccaEntity) {