butter-toast icon indicating copy to clipboard operation
butter-toast copied to clipboard

Prevent duplicate toasts

Open kleinph opened this issue 5 years ago • 2 comments

Is there a way to prevent duplicate toasts?

Some notification libs have a feature like that prevents duplicate toast messages popping up and instead extends the timeout of the already present notification. This could be done by comparing content or by specifying keys (messages with the same key replace each other).

Am I missing something or would this be a feature request? Thanks!

kleinph avatar Oct 04 '19 10:10 kleinph

Hey @kleinph, thanks for reaching out. The way butter-toast works at the moment is that you are the only one that controls the emission (raising) of toasts, and that BT is completely unaware of the content. One of the reasons is that BT can accept a component or a function as the toast content, which may not necessarily be equal when comparing, even if the output ends up being the same.

I do understand the need though, some events may fire twice, or multiple socket messages can send the same message. It can happen.

Thinking about the request makes me think it is not a binary thing. Sometimes you would like to not have your message appear more than once, but there may be cases in which you would (for example, a live like ticker as present in Instagram and Facebook), so I think it would be best to keep the control on the consumer side.

Here's a suggestion out of the top of my mind:

What if toasts had some sort of a mutual exclusion prop, and if a visible toast already has this tag present, the new toast won't be raised, and possibly, have its timeout reset. The mutual exclusion prop could be your text, for example - and then you, as a consumer maintain full control over this functionality.

What do you think?

ealush avatar Oct 09 '19 15:10 ealush

If there was a callback when a toast is closed (whether via click or timeout), then we could implement our own de-duplication system. At the moment, I think there is on a callback for the click?

hatton avatar Sep 23 '21 14:09 hatton