mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-16 14:30:36 +00:00
Compare commits
4 Commits
fix/Dropdo
...
newsletter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79593ce937 | ||
|
|
a0d27a5a83 | ||
|
|
1c4f6dc3f1 | ||
|
|
7d9a60973c |
145
src/components/ha-newsletter.ts
Normal file
145
src/components/ha-newsletter.ts
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
import "./ha-icon-button";
|
||||||
|
import "./ha-circular-progress";
|
||||||
|
import "@material/mwc-button/mwc-button";
|
||||||
|
import "./ha-card";
|
||||||
|
import "./ha-textfield";
|
||||||
|
import { LitElement, TemplateResult, html, CSSResultGroup, css } from "lit";
|
||||||
|
import { customElement, property, query } from "lit/decorators";
|
||||||
|
import { mdiClose } from "@mdi/js";
|
||||||
|
import type { HaTextField } from "./ha-textfield";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
|
import { LocalStorage } from "../common/decorators/local-storage";
|
||||||
|
|
||||||
|
@customElement("ha-newsletter")
|
||||||
|
class HaNewsletter extends LitElement {
|
||||||
|
@property({ attribute: false }) hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@query("ha-textfield")
|
||||||
|
private _emailField?: HaTextField;
|
||||||
|
|
||||||
|
@LocalStorage("dismissNewsletter", true)
|
||||||
|
private _dismissNewsletter = false;
|
||||||
|
|
||||||
|
private _requestStatus?: "inprogress" | "complete";
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (this._dismissNewsletter) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-card>
|
||||||
|
<div class="header">
|
||||||
|
${this.hass.localize("ui.newsletter.newsletter")}
|
||||||
|
<ha-icon-button
|
||||||
|
label="Dismiss"
|
||||||
|
.path=${mdiClose}
|
||||||
|
@click=${this._dismiss}
|
||||||
|
></ha-icon-button>
|
||||||
|
</div>
|
||||||
|
<div class="newsletter">
|
||||||
|
${this._requestStatus === "complete"
|
||||||
|
? html`<span>${this.hass.localize("ui.newsletter.thanks")}</span>`
|
||||||
|
: html`
|
||||||
|
<ha-textfield
|
||||||
|
required
|
||||||
|
type="email"
|
||||||
|
.label=${this.hass.localize("ui.newsletter.email")}
|
||||||
|
.validationMessage=${this.hass.localize(
|
||||||
|
"ui.newsletter.validation"
|
||||||
|
)}
|
||||||
|
></ha-textfield>
|
||||||
|
${this._requestStatus === "inprogress"
|
||||||
|
? html`
|
||||||
|
<ha-circular-progress
|
||||||
|
active
|
||||||
|
alt="Loading"
|
||||||
|
></ha-circular-progress>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<mwc-button
|
||||||
|
raised
|
||||||
|
.label=${this.hass.localize("ui.newsletter.subscribe")}
|
||||||
|
@click=${this._subscribe}
|
||||||
|
></mwc-button>
|
||||||
|
`}
|
||||||
|
`}
|
||||||
|
</div>
|
||||||
|
</ha-card>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _subscribe(): void {
|
||||||
|
if (!this._emailField?.reportValidity()) {
|
||||||
|
this._emailField!.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._requestStatus = "inprogress";
|
||||||
|
|
||||||
|
fetch(
|
||||||
|
`https://newsletter.home-assistant.io/subscribe?email=${
|
||||||
|
this._emailField!.value
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
this._requestStatus = "complete";
|
||||||
|
setTimeout(this._dismiss, 2000);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
// Reset request so user can re-enter email
|
||||||
|
this._requestStatus = undefined;
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dismiss(): void {
|
||||||
|
this._dismissNewsletter = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return css`
|
||||||
|
.newsletter {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding: 0 16px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
color: var(--ha-card-header-color, --primary-text-color);
|
||||||
|
font-family: var(--ha-card-header-font-family, inherit);
|
||||||
|
font-size: var(--ha-card-header-font-size, 24px);
|
||||||
|
letter-spacing: -0.012em;
|
||||||
|
line-height: 48px;
|
||||||
|
padding: 12px 16px 16px;
|
||||||
|
margin-block-start: 0px;
|
||||||
|
margin-block-end: 0px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-textfield {
|
||||||
|
flex: 1;
|
||||||
|
display: block;
|
||||||
|
padding-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
mwc-button {
|
||||||
|
padding-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-icon-button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-newsletter": HaNewsletter;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import "../../../components/ha-newsletter";
|
||||||
import { mdiCloudLock, mdiDotsVertical, mdiMagnify } from "@mdi/js";
|
import { mdiCloudLock, mdiDotsVertical, mdiMagnify } from "@mdi/js";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
@@ -134,6 +135,7 @@ class HaConfigDashboard extends LitElement {
|
|||||||
.pages=${configSections.dashboard}
|
.pages=${configSections.dashboard}
|
||||||
></ha-config-navigation>
|
></ha-config-navigation>
|
||||||
</ha-card>`}
|
</ha-card>`}
|
||||||
|
<ha-newsletter .hass=${this.hass}></ha-newsletter>
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
</ha-app-layout>
|
</ha-app-layout>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -972,6 +972,13 @@
|
|||||||
"triggered": "Triggered {name}",
|
"triggered": "Triggered {name}",
|
||||||
"dismiss": "Dismiss"
|
"dismiss": "Dismiss"
|
||||||
},
|
},
|
||||||
|
"newsletter": {
|
||||||
|
"newsletter": "Newsletter",
|
||||||
|
"email": "Email",
|
||||||
|
"validation": "A valid email address is required",
|
||||||
|
"subscribe": "Subscribe",
|
||||||
|
"thanks": "Thanks for subscribing!"
|
||||||
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"external_app_configuration": "App Configuration",
|
"external_app_configuration": "App Configuration",
|
||||||
"sidebar_toggle": "Sidebar Toggle",
|
"sidebar_toggle": "Sidebar Toggle",
|
||||||
|
|||||||
Reference in New Issue
Block a user