diff --git a/src/public/app/services/tasks.ts b/src/public/app/services/tasks.ts new file mode 100644 index 000000000..a5a6a9ceb --- /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 b3bb90da9..faf9a5687 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 = `
@@ -37,12 +38,28 @@ function buildTask(task: FTask) { export default class TaskListWidget extends TypeWidget { private $taskContainer!: JQuery; + private $addNewTask!: JQuery; 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) {