Files
frontend/src/data/persistent_notification.ts
Bram Kragten 82f80db558 Update typescript, prettier, tslint -> eslint (#5536)
* Update typescript, prettier, tslint -> eslint

* Organize imports

* Use glob for eslint fix react import
2020-04-14 09:05:45 -07:00

44 lines
973 B
TypeScript

import {
Connection,
createCollection,
HassEntity,
} from "home-assistant-js-websocket";
export interface PersitentNotificationEntity extends HassEntity {
notification_id?: string;
created_at?: string;
title?: string;
message?: string;
}
export interface PersistentNotification {
created_at: string;
message: string;
notification_id: string;
title: string;
status: "read" | "unread";
}
const fetchNotifications = (conn) =>
conn.sendMessagePromise({
type: "persistent_notification/get",
});
const subscribeUpdates = (conn, store) =>
conn.subscribeEvents(
() => fetchNotifications(conn).then((ntf) => store.setState(ntf, true)),
"persistent_notifications_updated"
);
export const subscribeNotifications = (
conn: Connection,
onChange: (notifications: PersistentNotification[]) => void
) =>
createCollection<PersistentNotification[]>(
"_ntf",
fetchNotifications,
subscribeUpdates,
conn,
onChange
);