Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 036c37b

Browse files
List only 1 'syncing to chain' ntfn
1 parent 762a801 commit 036c37b

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/action/notification.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ class NotificationAction {
99

1010
display({ type, msg, wait, err, handler, handlerLbl }) {
1111
if (err) log.error(msg, err);
12-
this._store.notifications.push({
13-
type: type || (err ? 'error' : 'info'),
14-
message: msg,
15-
waiting: wait,
16-
date: new Date(),
17-
handler: handler || (err ? () => this._nav.goCLI() : null),
18-
handlerLbl: handlerLbl || (err ? 'Show error logs' : null),
19-
display: true,
20-
});
12+
const ntfnCount = this._store.notifications.length;
13+
let prevNtfn = ntfnCount ? this._store.notifications[ntfnCount - 1] : null;
14+
if (prevNtfn && prevNtfn.message === msg) {
15+
prevNtfn.date = new Date();
16+
} else {
17+
this._store.notifications.push({
18+
type: type || (err ? 'error' : 'info'),
19+
message: msg,
20+
waiting: wait,
21+
date: new Date(),
22+
handler: handler || (err ? () => this._nav.goCLI() : null),
23+
handlerLbl: handlerLbl || (err ? 'Show error logs' : null),
24+
display: true,
25+
});
26+
}
2127
clearTimeout(this.tdisplay);
2228
this.tdisplay = setTimeout(() => this.close(), NOTIFICATION_DELAY);
2329
}

test/unit/action/notification.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ describe('Action Notification Unit Tests', () => {
8484
store.notifications[0].handler();
8585
expect(nav.goCLI, 'was called once');
8686
});
87+
88+
it('avoid redundant notifications but update date', async () => {
89+
notification.display({ msg: 'hello' });
90+
const date = store.notifications[0].date;
91+
await nap(10);
92+
notification.display({ msg: 'hello' });
93+
expect(store.notifications.length, 'to equal', 1);
94+
expect(store.notifications[0].date, 'not to equal', date);
95+
});
8796
});
8897

8998
describe('close()', () => {

0 commit comments

Comments
 (0)