Skip to content

Build your personal knowledge base with Trilium Notes

feat(client/tasks): create flow for creating a task

Elian Doranc00505cd7b73
diff --git a/src/public/app/services/tasks.ts b/src/public/app/services/tasks.ts
new file mode 100644
index 0000000000..a5a6a9ceb9
--- /dev/null
+++ b/src/public/app/services/tasks.ts
@@ -0,0 +1,7 @@
+import server from "./server.js";
+
+export async function createNewTask(title: string) {
+ await server.post(`tasks`, {
+ title
+ });
+}
diff --git a/src/public/app/widgets/type_widgets/task_list.ts b/src/public/app/widgets/type_widgets/task_list.ts
index b3bb90da96..faf9a56870 100644
--- a/src/public/app/widgets/type_widgets/task_list.ts
+++ b/src/public/app/widgets/type_widgets/task_list.ts
@@ -2,6 +2,7 @@ import type FNote from "../../entities/fnote.js";
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";
const TPL = `
<div class="note-detail-task-list note-detail-printable">
@@ -37,12 +38,28 @@ function buildTask(task: FTask) {
export default class TaskListWidget extends TypeWidget {
private $taskContainer!: JQuery<HTMLElement>;
+ private $addNewTask!: JQuery<HTMLElement>;
static getType() { return "taskList" }
doRender() {
this.$widget = $(TPL);
+ this.$addNewTask = this.$widget.find(".add-new-task");
this.$taskContainer = this.$widget.find(".task-container");
+
+ this.$addNewTask.on("keydown", (e) => {
+ if (e.key === "Enter") {
+ this.#createNewTask(String(this.$addNewTask.val()));
+ }
+ });
+ }
+
+ async #createNewTask(title: string) {
+ if (!title) {
+ return;
+ }
+
+ await taskService.createNewTask(title);
}
async doRefresh(note: FNote) {