mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
refactor: further improve task context types
This commit is contained in:
parent
4cd0702cbb
commit
39fecb3ffe
@ -82,7 +82,7 @@ ws.subscribeToMessages(async (message) => {
|
|||||||
|
|
||||||
toastService.showPersistent(toast);
|
toastService.showPersistent(toast);
|
||||||
|
|
||||||
if (typeof message.result === "object" && message.result.importedNoteId) {
|
if (message.result.importedNoteId) {
|
||||||
await appContext.tabManager.getActiveContext()?.setNote(message.result.importedNoteId);
|
await appContext.tabManager.getActiveContext()?.setNote(message.result.importedNoteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ ws.subscribeToMessages(async (message: WebSocketMessage) => {
|
|||||||
|
|
||||||
toastService.showPersistent(toast);
|
toastService.showPersistent(toast);
|
||||||
|
|
||||||
if (typeof message.result === "object" && message.result.parentNoteId) {
|
if (message.result.parentNoteId) {
|
||||||
await appContext.tabManager.getActiveContext()?.setNote(message.result.importedNoteId, {
|
await appContext.tabManager.getActiveContext()?.setNote(message.result.importedNoteId, {
|
||||||
viewScope: {
|
viewScope: {
|
||||||
viewMode: "attachments"
|
viewMode: "attachments"
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import type { TaskData } from "@triliumnext/commons";
|
import type { TaskType } from "@triliumnext/commons";
|
||||||
import ws from "./ws.js";
|
import ws from "./ws.js";
|
||||||
|
|
||||||
// taskId => TaskContext
|
// taskId => TaskContext
|
||||||
const taskContexts: Record<string, TaskContext> = {};
|
const taskContexts: Record<string, TaskContext<TaskType>> = {};
|
||||||
|
|
||||||
class TaskContext {
|
class TaskContext<TaskTypeT extends TaskType> {
|
||||||
private taskId: string;
|
private taskId: string;
|
||||||
private taskType: string | null;
|
private taskType: TaskType;
|
||||||
private progressCount: number;
|
private progressCount: number;
|
||||||
private lastSentCountTs: number;
|
private lastSentCountTs: number;
|
||||||
data: TaskData | null;
|
data: TaskData | null;
|
||||||
noteDeletionHandlerTriggered: boolean;
|
noteDeletionHandlerTriggered: boolean;
|
||||||
|
|
||||||
constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) {
|
constructor(taskId: string, taskType: TaskTypeT, data: {} | null = {}) {
|
||||||
this.taskId = taskId;
|
this.taskId = taskId;
|
||||||
this.taskType = taskType;
|
this.taskType = taskType;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@ -31,7 +31,7 @@ class TaskContext {
|
|||||||
this.increaseProgressCount();
|
this.increaseProgressCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance(taskId: string, taskType: string, data: {} | null = null): TaskContext {
|
static getInstance<TaskTypeT extends TaskType>(taskId: string, taskType: TaskTypeT, data: {} | null = null): TaskContext<TaskTypeT> {
|
||||||
if (!taskContexts[taskId]) {
|
if (!taskContexts[taskId]) {
|
||||||
taskContexts[taskId] = new TaskContext(taskId, taskType, data);
|
taskContexts[taskId] = new TaskContext(taskId, taskType, data);
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ export interface EntityChangeRecord {
|
|||||||
entity?: EntityRow;
|
entity?: EntityRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskStatus<TypeT, DataT> = {
|
type TaskStatus<TypeT, DataT, ResultT> = {
|
||||||
type: "taskProgressCount",
|
type: "taskProgressCount",
|
||||||
taskId: string;
|
taskId: string;
|
||||||
taskType: TypeT;
|
taskType: TypeT;
|
||||||
@ -288,18 +288,20 @@ type TaskStatus<TypeT, DataT> = {
|
|||||||
taskId: string;
|
taskId: string;
|
||||||
taskType: TypeT;
|
taskType: TypeT;
|
||||||
data: DataT;
|
data: DataT;
|
||||||
result?: string | Record<string, string | undefined>
|
result: ResultT;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskDefinitions =
|
type TaskDefinitions =
|
||||||
TaskStatus<"protectNotes", { protect: boolean; }>
|
TaskStatus<"protectNotes", { protect: boolean; }, null>
|
||||||
| TaskStatus<"importNotes", null>
|
| TaskStatus<"importNotes", null, { importedNoteId: string }>
|
||||||
| TaskStatus<"importAttachments", null>
|
| TaskStatus<"importAttachments", null, { parentNoteId?: string; importedNoteId: string }>
|
||||||
| TaskStatus<"deleteNotes", null>
|
| TaskStatus<"deleteNotes", null, null>
|
||||||
| TaskStatus<"undeleteNotes", null>
|
| TaskStatus<"undeleteNotes", null, null>
|
||||||
| TaskStatus<"export", null>
|
| TaskStatus<"export", null, null>
|
||||||
;
|
;
|
||||||
|
|
||||||
|
export type TaskType = TaskDefinitions["taskType"];
|
||||||
|
|
||||||
export interface OpenedFileUpdateStatus {
|
export interface OpenedFileUpdateStatus {
|
||||||
entityType: string;
|
entityType: string;
|
||||||
entityId: string;
|
entityId: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user