display notifications in a declarative way

This commit is contained in:
Géry Debongnie
2019-03-04 15:47:51 +01:00
parent 1833f9e4a9
commit ca5fa9ff18
9 changed files with 65 additions and 95 deletions
+2 -13
View File
@@ -13,9 +13,8 @@ import { Action } from "../store/action_manager_mixin";
export class Root extends Widget<Store, State> {
template = "web.web_client";
widgets = { Navbar, HomeMenu };
widgets = { Navbar, HomeMenu, Notification };
notifications: { [id: number]: Notification } = {};
store: Store;
constructor(env: Env, store: Store) {
@@ -23,22 +22,12 @@ export class Root extends Widget<Store, State> {
this.store = store;
this.state = store.state;
}
mounted() {
this.store.on("state_updated", this, newState => {
this.updateState(newState);
});
// notifications
this.store.on("notification_added", this, notif => {
const notification = new Notification(this, notif);
this.notifications[notif.id] = notification;
notification.mount(<any>this.refs.notification_container);
});
this.store.on("notification_closed", this, id => {
this.notifications[id].destroy();
delete this.notifications[id];
});
// loading indicator
this.store.on("rpc_status", this, status => {
const method = status === "loading" ? "remove" : "add";