feat(web-task): persist local drafts and save shortcut

This commit is contained in:
2026-04-05 23:59:03 +08:00
parent 8ef7c75948
commit 73e0f1312c
3 changed files with 189 additions and 24 deletions
+20
View File
@@ -35,9 +35,22 @@ export type LocalOpLogRecord = {
errorMessage: string | null;
};
export type LocalTaskDraftRecord = {
taskId: string;
userId: string;
title: string;
contentJson: string | null;
contentText: string;
priority: LocalTaskPriority;
status: LocalTaskStatus;
ddlInput: string;
updatedAt: number;
};
class TodoLocalDb extends Dexie {
declare tasks: Table<LocalTaskRecord, string>;
declare opLogs: Table<LocalOpLogRecord, string>;
declare taskDrafts: Table<LocalTaskDraftRecord, string>;
constructor() {
super("todolist-web-db");
@@ -47,8 +60,15 @@ class TodoLocalDb extends Dexie {
op_logs: "&opId,entityId,entityType,action,clientTs,syncedAt"
});
this.version(2).stores({
tasks: "&id,userId,status,priority,ddlAt,updatedAt,deletedAt",
op_logs: "&opId,entityId,entityType,action,clientTs,syncedAt",
task_drafts: "&taskId,userId,updatedAt"
});
this.tasks = this.table("tasks");
this.opLogs = this.table("op_logs");
this.taskDrafts = this.table("task_drafts");
}
}
@@ -0,0 +1,32 @@
import { localDb, type LocalTaskDraftRecord } from "@/services/local-db";
export type SaveLocalTaskDraftInput = {
taskId: string;
userId: string;
title: string;
contentJson: string | null;
contentText: string;
priority: LocalTaskDraftRecord["priority"];
status: LocalTaskDraftRecord["status"];
ddlInput: string;
};
export async function getLocalTaskDraft(taskId: string): Promise<LocalTaskDraftRecord | undefined> {
return localDb.taskDrafts.get(taskId);
}
export async function saveLocalTaskDraft(
input: SaveLocalTaskDraftInput
): Promise<LocalTaskDraftRecord> {
const draft: LocalTaskDraftRecord = {
...input,
updatedAt: Date.now()
};
await localDb.taskDrafts.put(draft);
return draft;
}
export async function deleteLocalTaskDraft(taskId: string): Promise<void> {
await localDb.taskDrafts.delete(taskId);
}