feat(calendar): allow dragging to set the time

This commit is contained in:
Elian Doran 2025-03-16 20:09:21 +02:00
parent 9412cfc19f
commit 680729de63
No known key found for this signature in database

View File

@ -189,27 +189,45 @@ export default class CalendarView extends ViewMode {
}
async #onCalendarSelection(e: DateSelectArg) {
// Handle start and end date
const startDate = CalendarView.#formatDateToLocalISO(e.start);
if (!startDate) {
return;
}
const endDate = CalendarView.#formatDateToLocalISO(CalendarView.#offsetDate(e.end, -1));
// Handle start and end time.
let startTime = null;
let endTime = null;
if (!e.allDay) {
startTime = CalendarView.#formatTimeToLocalISO(e.start);
endTime = CalendarView.#formatTimeToLocalISO(e.end);
}
// Ask for the title
const title = await dialogService.prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") });
if (!title?.trim()) {
return;
}
// Create the note.
const { note } = await server.post<CreateChildResponse>(`notes/${this.parentNote.noteId}/children?target=into`, {
title,
content: "",
type: "text"
});
// Set the attributes.
attributes.setLabel(note.noteId, "startDate", startDate);
if (endDate) {
attributes.setLabel(note.noteId, "endDate", endDate);
}
if (startTime) {
attributes.setLabel(note.noteId, "startTime", startTime);
}
if (endTime) {
attributes.setLabel(note.noteId, "endTime", endTime);
}
}
async #onEventMoved(e: EventChangeArg) {
@ -445,6 +463,18 @@ export default class CalendarView extends ViewMode {
return localDate.toISOString().split("T")[0];
}
static #formatTimeToLocalISO(date: Date | null | undefined) {
if (!date) {
return undefined;
}
const offset = date.getTimezoneOffset();
const localDate = new Date(date.getTime() - offset * 60 * 1000);
return localDate.toISOString()
.split("T")[1]
.substring(0, 5);
}
static #offsetDate(date: Date | string | null | undefined, offset: number) {
if (!date) {
return undefined;