fix: Improve toast messages to not show multiple of the same

This commit is contained in:
Tom Moor
2021-01-02 21:09:43 -08:00
parent 68bbd9fa34
commit bb81aa0065
5 changed files with 79 additions and 61 deletions

View File

@@ -25,6 +25,7 @@ class UiStore {
@observable mobileSidebarVisible: boolean = false;
@observable sidebarCollapsed: boolean = false;
@observable toasts: Map<string, Toast> = new Map();
lastToastId: string;
constructor() {
// Rehydrate
@@ -178,9 +179,19 @@ class UiStore {
) => {
if (!message) return;
const lastToast = this.toasts.get(this.lastToastId);
if (lastToast && lastToast.message === message) {
this.toasts.set(this.lastToastId, {
...lastToast,
reoccurring: lastToast.reoccurring ? ++lastToast.reoccurring : 1,
});
return;
}
const id = v4();
const createdAt = new Date().toISOString();
this.toasts.set(id, { message, createdAt, id, ...options });
this.lastToastId = id;
return id;
};