mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 10:32:27 +08:00
feat(tasks): support entities reloaded properly
This commit is contained in:
parent
f743f634b4
commit
034b93c99c
@ -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;
|
||||
|
@ -335,6 +335,8 @@ function processTaskChange(loadResults: LoadResults, ec: EntityChange) {
|
||||
froca.tasks[task.taskId] = task;
|
||||
}
|
||||
}
|
||||
|
||||
loadResults.addTaskRow(taskEntity);
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user