Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate toasts #127

Open
kleinph opened this issue Oct 4, 2019 · 2 comments
Open

Prevent duplicate toasts #127

kleinph opened this issue Oct 4, 2019 · 2 comments

Comments

@kleinph
Copy link

kleinph commented Oct 4, 2019

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!

@ealush
Copy link
Owner

ealush commented Oct 9, 2019

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?

@hatton
Copy link

hatton commented Sep 23, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants