Set initial calendar event date based on active calendar view (#14516)

This commit is contained in:
Philip Allgaier 2022-12-05 14:24:31 +01:00 committed by GitHub
parent 00274ebf66
commit 96080f3c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -73,7 +73,11 @@ class DialogCalendarEventEditor extends LitElement {
}
} else {
this._allDay = false;
this._dtstart = startOfHour(new Date());
// If we have been provided a selected date (e.g. based on the currently displayed
// day in a calendar view), use that as the starting value.
this._dtstart = startOfHour(
params.selectedDate ? params.selectedDate : new Date()
);
this._dtend = addHours(this._dtstart, 1);
}
}

View File

@ -276,8 +276,19 @@ export class HAFullCalendar extends LitElement {
}
private _createEvent(_info) {
// Logic for selectedDate: In week and day view, use the start of the week or the selected day.
// If we are in month view, we only use the start of the month, if we are not showing the
// current actual month, as for that one the current day is automatically highlighted and
// defaulting to a different day in the event creation dialog would be weird.
showCalendarEventEditDialog(this, {
calendars: this._mutableCalendars,
selectedDate:
this._activeView === "dayGridWeek" ||
this._activeView === "dayGridDay" ||
(this._activeView === "dayGridMonth" &&
this.calendar!.view.currentStart.getMonth() !== new Date().getMonth())
? this.calendar!.view.currentStart
: undefined,
updated: () => {
this._fireViewChanged();
},

View File

@ -2,7 +2,7 @@ import { fireEvent } from "../../common/dom/fire_event";
import { Calendar, CalendarEventData } from "../../data/calendar";
export interface CalendarEventDetailDialogParams {
calendars: Calendar[]; // When creating new events, is the list of events that support creation
calendars: Calendar[]; // When creating new events, is the list of calendar entities that support creation
calendarId?: string;
entry?: CalendarEventData;
canDelete?: boolean;

View File

@ -2,8 +2,9 @@ import { fireEvent } from "../../common/dom/fire_event";
import { Calendar, CalendarEventData } from "../../data/calendar";
export interface CalendarEventEditDialogParams {
calendars: Calendar[]; // When creating new events, is the list of events that support creation
calendars: Calendar[]; // When creating new events, is the list of calendar entities that support creation
calendarId?: string;
selectedDate?: Date; // When provided is used as the pre-filled date for the event creation dialog
entry?: CalendarEventData;
canDelete?: boolean;
updated: () => void;