Skip to content

Commit

Permalink
Various cleanups (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jun 10, 2023
1 parent 19e176c commit 8869ba7
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 90 deletions.
10 changes: 5 additions & 5 deletions src/components/dialogs/hacs-custom-repositories-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import "@material/mwc-linear-progress/mwc-linear-progress";
import { mdiDelete } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../homeassistant-frontend/src/common/dom/fire_event";
import { createCloseHeading } from "../../../homeassistant-frontend/src/components/ha-dialog";
import "../../../homeassistant-frontend/src/components/ha-form/ha-form";
import type { HaFormSchema } from "../../../homeassistant-frontend/src/components/ha-form/types";
import "../../../homeassistant-frontend/src/components/ha-settings-row";
import "../../../homeassistant-frontend/src/components/ha-svg-icon";
import type { HomeAssistant } from "../../../homeassistant-frontend/src/types";
import { HacsDispatchEvent } from "../../data/common";
import {
getRepositories,
repositoryAdd,
repositoryDelete,
websocketSubscription,
} from "../../data/websocket";
import type { HacsCustomRepositoriesDialogParams } from "./show-hacs-custom-repositories-dialog";
import { fireEvent } from "../../../homeassistant-frontend/src/common/dom/fire_event";
import type { HomeAssistant } from "../../../homeassistant-frontend/src/types";
import { createCloseHeading } from "../../../homeassistant-frontend/src/components/ha-dialog";
import type { HaFormSchema } from "../../../homeassistant-frontend/src/components/ha-form/types";
import type { HacsCustomRepositoriesDialogParams } from "./show-hacs-dialog";

@customElement("hacs-custom-repositories-dialog")
export class HacsCustomRepositoriesDialog extends LitElement {
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/hacs-download-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { repositoryBeta, websocketSubscription } from "../../data/websocket";
import { HacsStyles } from "../../styles/hacs-common-style";
import { generateFrontendResourceURL, updateFrontendResource } from "../../tools/frontend-resource";
import type { HacsDownloadDialogParams } from "./show-hacs-download-dialog";
import type { HacsDownloadDialogParams } from "./show-hacs-dialog";

@customElement("hacs-download-dialog")
export class HacsDonwloadDialog extends LitElement {
Expand Down
17 changes: 0 additions & 17 deletions src/components/dialogs/show-hacs-custom-repositories-dialog.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import type {
HaFormSchema,
} from "../../../homeassistant-frontend/src/components/ha-form/types";
import type { Hacs } from "../../data/hacs";
import type { RepositoryInfo } from "../../data/repository";

export interface HacsFormDialogParams {
interface BaseHacsDialogParams {
hacs: Hacs;
}

export interface HacsFormDialogParams extends BaseHacsDialogParams {
title: string;
schema?: readonly HaFormSchema[];
data?: HaFormDataContainer;
Expand All @@ -20,6 +24,13 @@ export interface HacsFormDialogParams {
saveAction?: (data: any) => Promise<void>;
}

export interface HacsDownloadDialogParams extends BaseHacsDialogParams {
repositoryId: string;
repository?: RepositoryInfo;
}

export interface HacsCustomRepositoriesDialogParams extends BaseHacsDialogParams {}

export const showHacsFormDialog = (
element: HTMLElement,
dialogParams: HacsFormDialogParams
Expand All @@ -30,3 +41,25 @@ export const showHacsFormDialog = (
dialogParams,
});
};

export const showHacsDownloadDialog = (
element: HTMLElement,
dialogParams: HacsDownloadDialogParams
): void => {
fireEvent(element, "show-dialog", {
dialogTag: "hacs-download-dialog",
dialogImport: () => import("./hacs-download-dialog"),
dialogParams,
});
};

export const showHacsCustomRepositoriesDialog = (
element: HTMLElement,
dialogParams: HacsCustomRepositoriesDialogParams
): void => {
fireEvent(element, "show-dialog", {
dialogTag: "hacs-custom-repositories-dialog",
dialogImport: () => import("./hacs-custom-repositories-dialog"),
dialogParams,
});
};
20 changes: 0 additions & 20 deletions src/components/dialogs/show-hacs-download-dialog.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/components/hacs-repository-owerflow-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import {
import memoizeOne from "memoize-one";
import { mainWindow } from "../../homeassistant-frontend/src/common/dom/get_main_window";
import { navigate } from "../../homeassistant-frontend/src/common/navigate";
import "../../homeassistant-frontend/src/components/ha-icon-overflow-menu";
import { getConfigEntries } from "../../homeassistant-frontend/src/data/config_entries";
import { deleteResource, fetchResources } from "../../homeassistant-frontend/src/data/lovelace";
import { showConfirmationDialog } from "../../homeassistant-frontend/src/dialogs/generic/show-dialog-box";
import type { RepositoryBase } from "../data/repository";
import { repositoryUninstall, repositoryUpdate } from "../data/websocket";
import type { HacsExperimentalPanel } from "../panels/hacs-experimental-panel";
import type { HacsRepositoryPanel } from "../panels/hacs-repository-panel";
import { showHacsDownloadDialog } from "./dialogs/show-hacs-download-dialog";
import { showHacsFormDialog } from "./dialogs/show-hacs-form-dialog";
import { showHacsDownloadDialog, showHacsFormDialog } from "./dialogs/show-hacs-dialog";

export const repositoryMenuItems = memoizeOne(
(element: HacsRepositoryPanel | HacsExperimentalPanel, repository: RepositoryBase) => [
Expand Down
2 changes: 0 additions & 2 deletions src/data/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { RepositoryBase } from "./repository";

export interface Route {
path: string;
prefix: string;
Expand Down
7 changes: 4 additions & 3 deletions src/hacs-my-redirect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { html, LitElement, TemplateResult } from "lit";
import type { TemplateResult } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { navigate } from "../homeassistant-frontend/src/common/navigate";
import {
Expand Down Expand Up @@ -64,11 +65,11 @@ class HacsMyRedirect extends LitElement {
navigate(url, { replace: true });
}

protected render(): TemplateResult {
protected render() {
if (this._error) {
return html`<hass-error-screen .error=${this._error}></hass-error-screen>`;
}
return html``;
return nothing;
}

private _createRedirectUrl(redirect: Redirect): string {
Expand Down
12 changes: 1 addition & 11 deletions src/hacs-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class HacsRouter extends HassRouterPage {
defaultPage: "dashboard",
showLoading: true,
beforeRender: (page: string) =>
!["_my_redirect", "dashboard", "entry", "explore", "repository"].includes(page)
? "dashboard"
: undefined,
!["_my_redirect", "repository"].includes(page) ? "dashboard" : undefined,
routes: {
_my_redirect: {
tag: "hacs-my-redirect",
Expand All @@ -75,14 +73,6 @@ class HacsRouter extends HassRouterPage {
tag: "hacs-experimental-panel",
load: () => import("./panels/hacs-experimental-panel"),
},
entry: {
tag: "hacs-experimental-panel",
load: () => import("./panels/hacs-experimental-panel"),
},
explore: {
tag: "hacs-experimental-panel",
load: () => import("./panels/hacs-experimental-panel"),
},
repository: {
tag: "hacs-repository-panel",
load: () => import("./panels/hacs-repository-panel"),
Expand Down
9 changes: 4 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { css, html, PropertyValues, TemplateResult } from "lit";
import type { PropertyValues } from "lit";
import { css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { applyThemesOnElement } from "../homeassistant-frontend/src/common/dom/apply_themes_on_element";
import { fireEvent } from "../homeassistant-frontend/src/common/dom/fire_event";
import { mainWindow } from "../homeassistant-frontend/src/common/dom/get_main_window";
import { isNavigationClick } from "../homeassistant-frontend/src/common/dom/is-navigation-click";
import { navigate } from "../homeassistant-frontend/src/common/navigate";
import { makeDialogManager } from "../homeassistant-frontend/src/dialogs/make-dialog-manager";
import "../homeassistant-frontend/src/layouts/hass-loading-screen";
import "../homeassistant-frontend/src/resources/ha-style";
import type { HomeAssistant, Route } from "../homeassistant-frontend/src/types";
import { HacsDispatchEvent, LocationChangedEvent } from "./data/common";
import type { Hacs } from "./data/hacs";
Expand Down Expand Up @@ -148,9 +147,9 @@ class HacsFrontend extends HacsElement {
}
}

protected render(): TemplateResult | void {
protected render() {
if (!this.hass || !this.hacs?.info.categories?.length || this.hacs?.localize === undefined) {
return html`<hass-loading-screen no-toolbar></hass-loading-screen>`;
return nothing;
}

return html`
Expand Down
14 changes: 9 additions & 5 deletions src/panels/hacs-experimental-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
} from "@mdi/js";
import "@polymer/app-layout/app-header/app-header";
import "@polymer/app-layout/app-toolbar/app-toolbar";
import { CSSResultGroup, LitElement, PropertyValues, TemplateResult, css, html } from "lit";
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators";
import memoize from "memoize-one";
import { relativeTime } from "../../homeassistant-frontend/src/common/datetime/relative_time";
Expand All @@ -34,17 +35,20 @@ import "../../homeassistant-frontend/src/components/ha-markdown";
import "../../homeassistant-frontend/src/components/ha-radio";
import "../../homeassistant-frontend/src/components/ha-select";

import "../../homeassistant-frontend/src/components/ha-icon-overflow-menu";
import { IconOverflowMenuItem } from "../../homeassistant-frontend/src/components/ha-icon-overflow-menu";
import "../../homeassistant-frontend/src/components/ha-menu-button";
import "../../homeassistant-frontend/src/components/ha-svg-icon";
import { haStyle } from "../../homeassistant-frontend/src/resources/styles";
import type { HomeAssistant, Route } from "../../homeassistant-frontend/src/types";
import { brandsUrl } from "../../homeassistant-frontend/src/util/brands-url";
import { showHacsCustomRepositoriesDialog } from "../components/dialogs/show-hacs-custom-repositories-dialog";
import { showHacsFormDialog } from "../components/dialogs/show-hacs-form-dialog";
import {
showHacsCustomRepositoriesDialog,
showHacsFormDialog,
} from "../components/dialogs/show-hacs-dialog";
import { repositoryMenuItems } from "../components/hacs-repository-owerflow-menu";
import { aboutHacsmarkdownContent } from "../data/about";
import { APP_FULL_NAME, Hacs } from "../data/hacs";
import type { Hacs } from "../data/hacs";
import { APP_FULL_NAME } from "../data/hacs";
import type { RepositoryBase, RepositoryCategory } from "../data/repository";
import { repositoriesClearNew } from "../data/websocket";
import { HacsStyles } from "../styles/hacs-common-style";
Expand Down
13 changes: 8 additions & 5 deletions src/panels/hacs-repository-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ import {
mdiExclamationThick,
mdiStar,
} from "@mdi/js";
import { LitElement, PropertyValues, TemplateResult, css, html } from "lit";
import type { PropertyValues, TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { mainWindow } from "../../homeassistant-frontend/src/common/dom/get_main_window";
import { extractSearchParamsObject } from "../../homeassistant-frontend/src/common/url/search-params";
import "../../homeassistant-frontend/src/components/ha-card";
import "../../homeassistant-frontend/src/components/ha-chip";
import "../../homeassistant-frontend/src/components/ha-fab";
import "../../homeassistant-frontend/src/components/ha-icon-overflow-menu";
import "../../homeassistant-frontend/src/components/ha-markdown";
import { showConfirmationDialog } from "../../homeassistant-frontend/src/dialogs/generic/show-dialog-box";
import "../../homeassistant-frontend/src/layouts/hass-error-screen";
import "../../homeassistant-frontend/src/layouts/hass-loading-screen";
import "../../homeassistant-frontend/src/layouts/hass-subpage";
import { HomeAssistant, Route } from "../../homeassistant-frontend/src/types";
import { showHacsDownloadDialog } from "../components/dialogs/show-hacs-download-dialog";
import type { HomeAssistant, Route } from "../../homeassistant-frontend/src/types";
import { showHacsDownloadDialog } from "../components/dialogs/show-hacs-dialog";
import { repositoryMenuItems } from "../components/hacs-repository-owerflow-menu";
import { Hacs } from "../data/hacs";
import { RepositoryBase, RepositoryInfo, fetchRepositoryInformation } from "../data/repository";
import type { Hacs } from "../data/hacs";
import type { RepositoryBase, RepositoryInfo } from "../data/repository";
import { fetchRepositoryInformation } from "../data/repository";
import { getRepositories, repositoryAdd } from "../data/websocket";
import { HacsStyles } from "../styles/hacs-common-style";
import { markdownWithRepositoryContext } from "../tools/markdown";
Expand Down
7 changes: 5 additions & 2 deletions src/tools/category-icon.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import memoizeOne from "memoize-one";
import {
mdiCodeBraces,
mdiDotNet,
Expand All @@ -7,7 +8,7 @@ import {
mdiRobot,
mdiViewDashboard,
} from "@mdi/js";
import { RepositoryCategory } from "../data/repository";
import type { RepositoryCategory } from "../data/repository";

const _IconMap = {
appdaemon: mdiRobot,
Expand All @@ -19,4 +20,6 @@ const _IconMap = {
theme: mdiPalette,
};

export const categoryIcon = (category: RepositoryCategory): string => _IconMap[category];
export const categoryIcon = memoizeOne(
(category: RepositoryCategory): string => _IconMap[category]
);
4 changes: 0 additions & 4 deletions src/tools/hacs-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ export class HacsLogger {
}

public log(content: string | unknown) {
// eslint-disable-next-line no-console
console.log(this.prefix, content);
}

public debug(content: string | unknown) {
// eslint-disable-next-line no-console
console.debug(this.prefix, content);
}

public warn(content: string | unknown) {
// eslint-disable-next-line no-console
console.warn(this.prefix, content);
}

public error(content: string | unknown) {
// eslint-disable-next-line no-console
console.error(this.prefix, content);
}
}
11 changes: 5 additions & 6 deletions src/tools/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ const showGitHubWeb = (text: string) =>
export const markdownWithRepositoryContext = (input: string, repository?: RepositoryInfo) => {
// Handle convertion to raw GitHub URL
input = input.replace(/(https:\/\/github\.com\/.*.\/blob*.[^\s]+)/g, function (x) {
if (showGitHubWeb(x)) {
return x;
}
return x
.replace("https://github.com/", "https://raw.githubusercontent.com/")
.replace("/blob/", "/");
return showGitHubWeb(x)
? x
: x
.replace("https://github.com/", "https://raw.githubusercontent.com/")
.replace("/blob/", "/");
});

// Handle relative links
Expand Down

0 comments on commit 8869ba7

Please sign in to comment.