From 034b93c99c293f81314df85de2927c2c6bf994f1 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 19 Feb 2025 21:27:02 +0200 Subject: [PATCH] feat(tasks): support entities reloaded properly --- src/becca/becca-interface.ts | 4 ++++ src/public/app/services/froca_updater.ts | 2 ++ src/public/app/services/load_results.ts | 15 ++++++++++++++- src/public/app/widgets/type_widgets/task_list.ts | 5 +++++ src/services/ws.ts | 6 ++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 16d81d3df..82970907b 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>(entityName: string, entityId: string): AbstractBeccaEntity | 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 617c4c277..cf9dbbad0 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 5ebfc7be5..e91dfde86 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> = {}; @@ -97,6 +99,8 @@ export default class LoadResults { this.optionNames = []; this.attachmentRows = []; + + this.taskRows = []; } getEntityRow(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 861ebe634..b54ee35c7 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 = `
@@ -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 e163e25d7..f46a9b3f7 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) {