From 7cba5a7c7d87761f3dda9b0c66cb1644517998fe Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 18 Feb 2025 19:58:00 +0200 Subject: [PATCH] feat(client/tasks): display tasks --- src/public/app/entities/ftask.ts | 31 +++++++++++++++++++ src/public/app/services/froca.ts | 18 +++++++++++ .../app/widgets/type_widgets/task_list.ts | 19 +++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/public/app/entities/ftask.ts diff --git a/src/public/app/entities/ftask.ts b/src/public/app/entities/ftask.ts new file mode 100644 index 000000000..b6e70b00b --- /dev/null +++ b/src/public/app/entities/ftask.ts @@ -0,0 +1,31 @@ +import type { Froca } from "../services/froca-interface.js"; + +export interface FTaskRow { + taskId: string; + parentNoteId: string; + title: string; + dueDate?: string; + isDone?: boolean; +} + +export default class FTask { + private froca: Froca; + taskId!: string; + parentNoteId!: string; + title!: string; + dueDate?: string; + isDone!: boolean; + + constructor(froca: Froca, row: FTaskRow) { + this.froca = froca; + this.update(row); + } + + update(row: FTaskRow) { + this.taskId = row.taskId; + this.parentNoteId = row.parentNoteId; + this.title = row.title; + this.dueDate = row.dueDate; + this.isDone = !!row.isDone; + } +} diff --git a/src/public/app/services/froca.ts b/src/public/app/services/froca.ts index 8849d6331..36e25a5a0 100644 --- a/src/public/app/services/froca.ts +++ b/src/public/app/services/froca.ts @@ -6,6 +6,8 @@ import appContext from "../components/app_context.js"; import FBlob, { type FBlobRow } from "../entities/fblob.js"; import FAttachment, { type FAttachmentRow } from "../entities/fattachment.js"; import type { Froca } from "./froca-interface.js"; +import FTask from "../entities/ftask.js"; +import type { FTaskRow } from "../entities/ftask.js"; interface SubtreeResponse { notes: FNoteRow[]; @@ -37,6 +39,7 @@ class FrocaImpl implements Froca { attributes!: Record; attachments!: Record; blobPromises!: Record | null>; + tasks!: Record; constructor() { this.initializedPromise = this.loadInitialTree(); @@ -52,6 +55,7 @@ class FrocaImpl implements Froca { this.attributes = {}; this.attachments = {}; this.blobPromises = {}; + this.tasks = {}; this.addResp(resp); } @@ -368,6 +372,20 @@ class FrocaImpl implements Froca { }); } + async getTasks() { + const taskRows = await server.get(`tasks`); + return this.processTaskRow(taskRows); + } + + processTaskRow(taskRows: FTaskRow[]): FTask[] { + return taskRows.map((taskRow) => { + const task = new FTask(this, taskRow); + this.tasks[task.taskId] = task; + + return task; + }); + } + async getBlob(entityType: string, entityId: string) { // I'm not sure why we're not using blobIds directly, it would save us this composite key ... // perhaps one benefit is that we're always requesting the latest blob, not relying on perhaps faulty/slow diff --git a/src/public/app/widgets/type_widgets/task_list.ts b/src/public/app/widgets/type_widgets/task_list.ts index 30a5572a2..41abe01e2 100644 --- a/src/public/app/widgets/type_widgets/task_list.ts +++ b/src/public/app/widgets/type_widgets/task_list.ts @@ -1,18 +1,28 @@ 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"; const TPL = `
- Task list goes here. +
+
`; +function buildTask(task: FTask) { + return `
${task.title}
`; +} + export default class TaskListWidget extends TypeWidget { + private $taskContainer!: JQuery; + static getType() { return "taskList" } doRender() { this.$widget = $(TPL); + this.$taskContainer = this.$widget.find(".task-container"); } async doRefresh(note: FNote) { @@ -21,6 +31,13 @@ export default class TaskListWidget extends TypeWidget { if (!this.note) { return; } + + this.$taskContainer.clearQueue(); + + const tasks = await froca.getTasks(); + for (const task of tasks) { + this.$taskContainer.append($(buildTask(task))); + } } }