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

This commit is contained in:
Elian Doran 2025-02-18 21:06:51 +02:00
parent fc1ee7c6f0
commit c00505cd7b
No known key found for this signature in database
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import server from "./server.js";
export async function createNewTask(title: string) {
await server.post(`tasks`, {
title
});
}

View File

@ -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) {