Skip to content

Commit

Permalink
Add button to create local calendar in calendar panel (#18377)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Oct 24, 2023
1 parent c0dfc9f commit ccba7a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/panels/calendar/ha-panel-calendar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ResizeController } from "@lit-labs/observers/resize-controller";
import "@material/mwc-list";
import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
import { mdiChevronDown, mdiRefresh } from "@mdi/js";
import { mdiChevronDown, mdiPlus, mdiRefresh } from "@mdi/js";
import {
CSSResultGroup,
LitElement,
Expand Down Expand Up @@ -32,6 +32,8 @@ import {
fetchCalendarEvents,
getCalendars,
} from "../../data/calendar";
import { fetchIntegrationManifest } from "../../data/integration";
import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow";
import { haStyle } from "../../resources/styles";
import type { CalendarViewChanged, HomeAssistant } from "../../types";
import "./ha-full-calendar";
Expand Down Expand Up @@ -119,7 +121,7 @@ class PanelCalendar extends LitElement {
);
const showPane = this._showPaneController.value ?? !this.narrow;
return html`
<ha-two-pane-top-app-bar-fixed .pane=${showPane}>
<ha-two-pane-top-app-bar-fixed .pane=${showPane} footer>
<ha-menu-button
slot="navigationIcon"
.hass=${this.hass}
Expand All @@ -146,6 +148,11 @@ class PanelCalendar extends LitElement {
></ha-svg-icon>
</ha-button>
${calendarItems}
<li divider role="separator"></li>
<ha-list-item graphic="icon" @click=${this._addCalendar}>
<ha-svg-icon .path=${mdiPlus} slot="graphic"></ha-svg-icon>
${this.hass.localize("ui.components.calendar.create_calendar")}
</ha-list-item>
</ha-button-menu>`
: html`<div slot="title">
${this.hass.localize("ui.components.calendar.my_calendars")}
Expand All @@ -157,7 +164,15 @@ class PanelCalendar extends LitElement {
@click=${this._handleRefresh}
></ha-icon-button>
${showPane
? html`<mwc-list slot="pane" multi}>${calendarItems}</mwc-list>`
? html`<mwc-list slot="pane" multi}>${calendarItems}</mwc-list>
<ha-list-item
graphic="icon"
slot="pane-footer"
@click=${this._addCalendar}
>
<ha-svg-icon .path=${mdiPlus} slot="graphic"></ha-svg-icon>
${this.hass.localize("ui.components.calendar.create_calendar")}
</ha-list-item>`
: nothing}
<ha-full-calendar
.events=${this._events}
Expand Down Expand Up @@ -219,6 +234,19 @@ class PanelCalendar extends LitElement {
}
}

private async _addCalendar(): Promise<void> {
showConfigFlowDialog(this, {
startFlowHandler: "local_calendar",
showAdvanced: this.hass.userData?.showAdvanced,
manifest: await fetchIntegrationManifest(this.hass, "local_calendar"),
dialogClosedCallback: ({ flowFinished }) => {
if (flowFinished) {
this._calendars = getCalendars(this.hass);
}
},
});
}

private async _handleViewChanged(
ev: HASSDomEvent<CalendarViewChanged>
): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@
"calendar": {
"label": "Calendar",
"my_calendars": "My calendars",
"create_calendar": "Create calendar",
"today": "Today",
"event_retrieval_error": "Could not retrieve events for calendars:",
"event": {
Expand Down

0 comments on commit ccba7a7

Please sign in to comment.