feat(calendar_view): render notes by their start date

This commit is contained in:
Elian Doran 2025-02-15 10:43:46 +02:00
parent 4dc2803cc6
commit 64b446315d
No known key found for this signature in database

View File

@ -1,3 +1,5 @@
import type { EventSourceInput } from "@fullcalendar/core";
import froca from "../../services/froca.js";
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
const TPL = `
@ -25,12 +27,14 @@ export default class CalendarView extends ViewMode {
private $root: JQuery<HTMLElement>;
private $calendarContainer: JQuery<HTMLElement>;
private noteIds: string[];
constructor(args: ViewModeArgs) {
super(args);
this.$root = $(TPL);
this.$calendarContainer = this.$root.find(".calendar-container");
this.noteIds = args.noteIds;
args.$parent.append(this.$root);
}
@ -40,11 +44,32 @@ export default class CalendarView extends ViewMode {
const calendar = new Calendar(this.$calendarContainer[0], {
plugins: [ dayGridPlugin ],
initialView: "dayGridMonth"
initialView: "dayGridMonth",
events: await CalendarView.#buildEvents(this.noteIds)
});
calendar.render();
return this.$root;
}
static async #buildEvents(noteIds: string[]) {
const notes = await froca.getNotes(noteIds);
const events: EventSourceInput = [];
for (const note of notes) {
const startDate = note.getAttributeValue("label", "startDate");
if (!startDate) {
continue;
}
events.push({
title: note.title,
start: startDate
});
}
return events;
}
}