diff --git a/src/panels/calendar/confirm-event-dialog-box.ts b/src/panels/calendar/confirm-event-dialog-box.ts index 43564939d6..aa11008db6 100644 --- a/src/panels/calendar/confirm-event-dialog-box.ts +++ b/src/panels/calendar/confirm-event-dialog-box.ts @@ -1,9 +1,10 @@ import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../common/dom/fire_event"; -import "../../components/ha-dialog"; +import "../../components/ha-dialog-footer"; import "../../components/ha-svg-icon"; import "../../components/ha-switch"; +import "../../components/ha-wa-dialog"; import { RecurrenceRange } from "../../data/calendar"; import type { HomeAssistant } from "../../types"; import type { ConfirmEventDialogBoxParams } from "./show-confirm-event-dialog-box"; @@ -15,11 +16,21 @@ class ConfirmEventDialogBox extends LitElement { @state() private _params?: ConfirmEventDialogBoxParams; + @state() private _open = false; + + @state() + private _closeState?: "canceled" | "confirmed" | "confirmedFuture"; + public async showDialog(params: ConfirmEventDialogBoxParams): Promise { this._params = params; + this._open = true; } public closeDialog(): boolean { + if (!this._open) { + return true; + } + this._open = false; return true; } @@ -29,80 +40,82 @@ class ConfirmEventDialogBox extends LitElement { } return html` -

${this._params.text}

- - ${this.hass.localize("ui.common.cancel")} - - - ${this._params.confirmText} - - ${this._params.confirmFutureText - ? html` - - ${this._params.confirmFutureText} - - ` - : ""} -
+ + + ${this.hass.localize("ui.common.cancel")} + + + ${this._params.confirmText} + + ${this._params.confirmFutureText + ? html` + + ${this._params.confirmFutureText} + + ` + : ""} + + `; } private _dismiss(): void { - if (this._params!.cancel) { - this._params!.cancel(); - } - this._close(); + this._closeState = "canceled"; + this.closeDialog(); } private _confirm(): void { + this._closeState = "confirmed"; if (this._params!.confirm) { this._params!.confirm(RecurrenceRange.THISEVENT); } - this._close(); + this.closeDialog(); } private _confirmFuture(): void { + this._closeState = "confirmedFuture"; if (this._params!.confirm) { this._params!.confirm(RecurrenceRange.THISANDFUTURE); } - this._close(); + this.closeDialog(); } - private _dialogClosed(ev) { - if (ev.detail.action === "ignore") { - return; - } - this._dismiss(); - } - - private _close(): void { + private _dialogClosed(): void { if (!this._params) { return; } + if ( + this._closeState !== "confirmed" && + this._closeState !== "confirmedFuture" + ) { + this._params.cancel?.(); + } this._params = undefined; + this._open = false; + this._closeState = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); } @@ -124,15 +137,10 @@ class ConfirmEventDialogBox extends LitElement { .secondary { color: var(--secondary-text-color); } - ha-dialog { + ha-wa-dialog { /* Place above other dialogs */ --dialog-z-index: 104; } - @media all and (min-width: 600px) { - ha-dialog { - --mdc-dialog-min-width: 400px; - } - } ha-textfield { width: 100%; } diff --git a/src/panels/calendar/dialog-calendar-event-detail.ts b/src/panels/calendar/dialog-calendar-event-detail.ts index 50645b2bd2..69f2721ec4 100644 --- a/src/panels/calendar/dialog-calendar-event-detail.ts +++ b/src/panels/calendar/dialog-calendar-event-detail.ts @@ -13,8 +13,9 @@ import "../../components/entity/state-info"; import "../../components/ha-alert"; import "../../components/ha-button"; import "../../components/ha-date-input"; -import { createCloseHeading } from "../../components/ha-dialog"; +import "../../components/ha-dialog-footer"; import "../../components/ha-time-input"; +import "../../components/ha-wa-dialog"; import type { CalendarEventMutableParams } from "../../data/calendar"; import { deleteCalendarEvent } from "../../data/calendar"; import { haStyleDialog } from "../../resources/styles"; @@ -32,6 +33,8 @@ class DialogCalendarEventDetail extends LitElement { @state() private _params?: CalendarEventDetailDialogParams; + @state() private _open = false; + @state() private _calendarId?: string; @state() private _submitting = false; @@ -44,6 +47,7 @@ class DialogCalendarEventDetail extends LitElement { params: CalendarEventDetailDialogParams ): Promise { this._params = params; + this._open = true; if (params.entry) { const entry = params.entry!; this._data = entry; @@ -52,9 +56,7 @@ class DialogCalendarEventDetail extends LitElement { } public closeDialog(): void { - this._calendarId = undefined; - this._params = undefined; - fireEvent(this, "dialog-closed", { dialog: this.localName }); + this._open = false; } protected render() { @@ -63,12 +65,11 @@ class DialogCalendarEventDetail extends LitElement { } const stateObj = this.hass.states[this._calendarId!]; return html` -
${this._error @@ -100,32 +101,41 @@ class DialogCalendarEventDetail extends LitElement { >
- ${this._params.canDelete - ? html` - + ${this._params.canDelete + ? html` + + ${this.hass.localize("ui.components.calendar.event.delete")} + + ` + : ""} + ${this._params.canEdit + ? html` - ${this.hass.localize("ui.components.calendar.event.delete")} - - ` - : ""} - ${this._params.canEdit - ? html` - ${this.hass.localize("ui.components.calendar.event.edit")} - ` - : ""} -
+ ${this.hass.localize("ui.components.calendar.event.edit")} + ` + : ""} + + `; } + private _dialogClosed(): void { + this._calendarId = undefined; + this._params = undefined; + this._open = false; + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } + private _renderRRuleAsText(value: string) { if (!value) { return ""; diff --git a/src/panels/calendar/dialog-calendar-event-editor.ts b/src/panels/calendar/dialog-calendar-event-editor.ts index 20707022a2..24d938c23c 100644 --- a/src/panels/calendar/dialog-calendar-event-editor.ts +++ b/src/panels/calendar/dialog-calendar-event-editor.ts @@ -19,12 +19,13 @@ import "../../components/entity/ha-entity-picker"; import "../../components/ha-alert"; import "../../components/ha-button"; import "../../components/ha-date-input"; -import { createCloseHeading } from "../../components/ha-dialog"; +import "../../components/ha-dialog-footer"; import "../../components/ha-formfield"; import "../../components/ha-switch"; import "../../components/ha-textarea"; import "../../components/ha-textfield"; import "../../components/ha-time-input"; +import "../../components/ha-wa-dialog"; import type { CalendarEventMutableParams } from "../../data/calendar"; import { CalendarEntityFeature, @@ -57,6 +58,8 @@ class DialogCalendarEventEditor extends LitElement { @state() private _params?: CalendarEventEditDialogParams; + @state() private _open = false; + @state() private _calendarId?: string; @state() private _summary = ""; @@ -87,6 +90,7 @@ class DialogCalendarEventEditor extends LitElement { this._error = undefined; this._info = undefined; this._params = params; + this._open = true; this._calendarId = params.calendarId || Object.values(this.hass.states).find( @@ -129,19 +133,7 @@ class DialogCalendarEventEditor extends LitElement { } public closeDialog(): void { - if (!this._params) { - return; - } - this._calendarId = undefined; - this._params = undefined; - this._dtstart = undefined; - this._dtend = undefined; - this._summary = ""; - this._description = ""; - this._location = ""; - this._hasLocation = false; - this._rrule = undefined; - fireEvent(this, "dialog-closed", { dialog: this.localName }); + this._open = false; } protected render() { @@ -156,17 +148,14 @@ class DialogCalendarEventEditor extends LitElement { ); return html` -
${this._error @@ -189,7 +178,7 @@ class DialogCalendarEventEditor extends LitElement { required @input=${this._handleSummaryChanged} .validationMessage=${this.hass.localize("ui.common.error_required")} - dialogInitialFocus + autofocus >
- ${isCreate - ? html` - - ${this.hass.localize("ui.components.calendar.event.add")} - - ` - : html` - - ${this.hass.localize("ui.components.calendar.event.save")} - - ${this._params.canDelete - ? html` - - ${this.hass.localize( - "ui.components.calendar.event.delete" - )} - - ` - : ""} - `} -
+ + ${isCreate + ? html` + + ${this.hass.localize("ui.components.calendar.event.add")} + + ` + : html` + ${this._params.canDelete + ? html` + + ${this.hass.localize( + "ui.components.calendar.event.delete" + )} + + ` + : ""} + + ${this.hass.localize("ui.components.calendar.event.save")} + + `} + + `; } + private _dialogClosed(): void { + if (!this._params) { + return; + } + this._calendarId = undefined; + this._params = undefined; + this._dtstart = undefined; + this._dtend = undefined; + this._summary = ""; + this._description = ""; + this._location = ""; + this._hasLocation = false; + this._rrule = undefined; + this._open = false; + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } + private _isEditableCalendar = (entityStateObj: HassEntity) => supportsFeature(entityStateObj, CalendarEntityFeature.CREATE_EVENT); @@ -609,12 +617,6 @@ class DialogCalendarEventEditor extends LitElement { return [ haStyleDialog, css` - @media all and (min-width: 450px) and (min-height: 500px) { - ha-dialog { - --mdc-dialog-min-width: min(600px, 95vw); - --mdc-dialog-max-width: min(600px, 95vw); - } - } state-info { line-height: 40px; }