mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 18:50:41 +01:00
fix(views/table): unable to update state for newly created rows
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { EventData } from "../../components/app_context.js";
|
||||
import appContext from "../../components/app_context.js";
|
||||
import Component from "../../components/component.js";
|
||||
import type FNote from "../../entities/fnote.js";
|
||||
import type { ViewTypeOptions } from "../../services/note_list_renderer.js";
|
||||
@@ -8,7 +9,6 @@ export interface ViewModeArgs {
|
||||
$parent: JQuery<HTMLElement>;
|
||||
parentNote: FNote;
|
||||
parentNotePath?: string | null;
|
||||
noteIds: string[];
|
||||
showNotePath?: boolean;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ export default abstract class ViewMode<T extends object> extends Component {
|
||||
private _viewStorage: ViewModeStorage<T> | null;
|
||||
protected parentNote: FNote;
|
||||
protected viewType: ViewTypeOptions;
|
||||
protected noteIds: string[];
|
||||
protected args: ViewModeArgs;
|
||||
|
||||
constructor(args: ViewModeArgs, viewType: ViewTypeOptions) {
|
||||
super();
|
||||
@@ -25,6 +27,12 @@ export default abstract class ViewMode<T extends object> extends Component {
|
||||
// note list must be added to the DOM immediately, otherwise some functionality scripting (canvas) won't work
|
||||
args.$parent.empty();
|
||||
this.viewType = viewType;
|
||||
this.args = args;
|
||||
this.noteIds = [];
|
||||
}
|
||||
|
||||
async beforeRender() {
|
||||
await this.#refreshNoteIds();
|
||||
}
|
||||
|
||||
abstract renderList(): Promise<JQuery<HTMLElement> | undefined>;
|
||||
@@ -39,6 +47,16 @@ export default abstract class ViewMode<T extends object> extends Component {
|
||||
// Do nothing by default.
|
||||
}
|
||||
|
||||
entitiesReloadedEvent(e: EventData<"entitiesReloaded">) {
|
||||
if (e.loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))) {
|
||||
this.#refreshNoteIds();
|
||||
}
|
||||
|
||||
if (this.onEntitiesReloaded(e)) {
|
||||
appContext.triggerEvent("refreshNoteList", { noteId: this.parentNote.noteId });
|
||||
}
|
||||
}
|
||||
|
||||
get isReadOnly() {
|
||||
return this.parentNote.hasLabel("readOnly");
|
||||
}
|
||||
@@ -52,4 +70,14 @@ export default abstract class ViewMode<T extends object> extends Component {
|
||||
return this._viewStorage;
|
||||
}
|
||||
|
||||
async #refreshNoteIds() {
|
||||
let noteIds: string[];
|
||||
if (this.viewType === "list" || this.viewType === "grid") {
|
||||
noteIds = this.args.parentNote.getChildNoteIds();
|
||||
} else {
|
||||
noteIds = await this.args.parentNote.getSubtreeNoteIds();
|
||||
}
|
||||
this.noteIds = noteIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user