Skip to content

Commit

Permalink
Add dismiss new to overflow menu (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jan 26, 2024
1 parent 04fffaa commit be4081e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
19 changes: 16 additions & 3 deletions src/components/hacs-repository-owerflow-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
mdiGithub,
mdiInformation,
mdiLanguageJavascript,
mdiMoonNew,
mdiReload,
} from "@mdi/js";
import memoizeOne from "memoize-one";
Expand All @@ -18,14 +19,18 @@ import {
} from "../../homeassistant-frontend/src/data/lovelace/resource";
import { showConfirmationDialog } from "../../homeassistant-frontend/src/dialogs/generic/show-dialog-box";
import type { RepositoryBase } from "../data/repository";
import { repositoryUninstall, repositoryUpdate } from "../data/websocket";
import {
repositoriesClearNewRepository,
repositoryUninstall,
repositoryUpdate,
} from "../data/websocket";
import type { HacsDashboard } from "../dashboards/hacs-dashboard";
import type { HacsRepositoryDashboard } from "../dashboards/hacs-repository-dashboard";
import { showHacsDownloadDialog, showHacsFormDialog } from "./dialogs/show-hacs-dialog";

export const repositoryMenuItems = memoizeOne(
(element: HacsRepositoryDashboard | HacsDashboard, repository: RepositoryBase) => [
...(element.nodeName === "HACS-EXPERIMENTAL-PANEL"
...(element.nodeName === "HACS-DASHBOARD"
? [
{
path: mdiInformation,
Expand Down Expand Up @@ -58,7 +63,15 @@ export const repositoryMenuItems = memoizeOne(
hideForUninstalled: true,
},
]
: []),
: repository.new
? [
{
path: mdiMoonNew,
label: element.hacs.localize("repository_card.dismiss_new"),
action: () => repositoriesClearNewRepository(element.hass, repository.id),
},
]
: []),
...(repository.category === "plugin" && repository.installed_version
? [
{
Expand Down
19 changes: 8 additions & 11 deletions src/dashboards/hacs-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,14 @@ export class HacsDashboard extends LitElement {
title: "",
width: this.narrow ? undefined : "10%",
type: "overflow-menu",
template: (repository: RepositoryBase) =>
repository.installed
? html`
<ha-icon-overflow-menu
.hass=${this.hass}
.items=${repositoryMenuItems(this, repository) as IconOverflowMenuItem[]}
narrow
>
</ha-icon-overflow-menu>
`
: "",
template: (repository: RepositoryBase) => html`
<ha-icon-overflow-menu
.hass=${this.hass}
.items=${repositoryMenuItems(this, repository) as IconOverflowMenuItem[]}
narrow
>
</ha-icon-overflow-menu>
`,
},
}),
);
Expand Down
8 changes: 7 additions & 1 deletion src/data/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ export const repositoriesClearNew = async (hass: HomeAssistant, hacs: Hacs) =>
categories: hacs.info.categories,
});

export const repositoriesClearNewRepository = async (hass: HomeAssistant, repository: string) =>
hass.connection.sendMessagePromise<void>({
type: "hacs/repositories/clear_new",
repository,
});

export const websocketSubscription = (
hass: HomeAssistant,
onChange: (result: Record<any, any> | null) => void,
event: HacsDispatchEvent
event: HacsDispatchEvent,
) =>
hass.connection.subscribeMessage(onChange, {
type: "hacs/subscribe",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
},
"repository_card": {
"dismiss": "dismiss",
"dismiss_new": "Dismiss new",
"information": "Information",
"new_repository": "New repository",
"not_loaded": "Not loaded",
Expand Down

0 comments on commit be4081e

Please sign in to comment.