Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to create local calendar in calendar panel #18377

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading