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

Fix update issue in custom repositories dialog #534

Merged
merged 1 commit into from
Nov 13, 2021
Merged
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
12 changes: 8 additions & 4 deletions src/components/dialogs/hacs-custom-repositories-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 { Repository } from "../../data/common";
import { getRepositories, repositoryAdd, repositoryDelete } from "../../data/websocket";
import { scrollBarStyle } from "../../styles/element-styles";
import { HacsStyles } from "../../styles/hacs-common-style";
Expand All @@ -23,19 +24,21 @@ export class HacsCustomRepositoriesDialog extends HacsDialogBase {

@state() private _addRepositoryData = { category: undefined, repository: undefined };

@state() private _customRepositories?: Repository[];

shouldUpdate(changedProperties: PropertyValues) {
return (
changedProperties.has("narrow") ||
changedProperties.has("active") ||
changedProperties.has("_error") ||
changedProperties.has("_addRepositoryData") ||
changedProperties.has("_customRepositories") ||
changedProperties.has("_progress")
);
}

protected render(): TemplateResult | void {
if (!this.active) return html``;
const repositories = this.hacs.repositories?.filter((repo) => repo.custom);
const addRepositorySchema: HaFormSchema[] = [
{
type: "string",
Expand Down Expand Up @@ -67,7 +70,7 @@ export class HacsCustomRepositoriesDialog extends HacsDialogBase {
${this._error.message}
</ha-alert>`
: ""}
${repositories
${this._customRepositories
?.filter((repo) => this.hacs.configuration.categories.includes(repo.category))
.map(
(repo) => html`<ha-settings-row
Expand Down Expand Up @@ -116,6 +119,7 @@ export class HacsCustomRepositoriesDialog extends HacsDialogBase {

protected firstUpdated() {
this.hass.connection.subscribeEvents((msg) => (this._error = (msg as any).data), "hacs/error");
this._customRepositories = this.hacs.repositories?.filter((repo) => repo.custom);
}

private _valueChanged(ev) {
Expand Down Expand Up @@ -150,11 +154,11 @@ export class HacsCustomRepositoriesDialog extends HacsDialogBase {
composed: true,
})
);
this._customRepositories = repositories.filter((repo) => repo.custom);
this._progress = false;
}

private async _removeRepository(repository: string) {
this._progress = true;
this._error = undefined;
await repositoryDelete(this.hass, repository);
const repositories = await getRepositories(this.hass);
Expand All @@ -165,7 +169,7 @@ export class HacsCustomRepositoriesDialog extends HacsDialogBase {
composed: true,
})
);
this._progress = false;
this._customRepositories = repositories.filter((repo) => repo.custom);
}

private async _showReopsitoryInfo(repository: string) {
Expand Down