react-toastify icon indicating copy to clipboard operation
react-toastify copied to clipboard

Limit the waiting queue to 2 toasts

Open AdrienLemaire opened this issue 2 years ago • 6 comments

Do you want to request a feature or report a bug? feature

What is the current behavior? When using limit, all pending toasts will be queued. Coming after a while, toasts will start playing from the most recent to the oldest one.

What is the expected behavior? We would like to keep a limit=1 with a queueMax=2 (property not existing at the moment), so that we aren't spammed by toasts when coming back to the page after a while, especially since old toasts have become irrelevant by now. We want to keep the 2 most recent notifications in the queue, thus the newest toast should remove the second oldest toast from the queue.

Would it be possible to add this new property to a container ? Or maybe add another param to ClearWaitingQueueParams when calling toast.clearWaitingQueue ?

Thank you for considering this feature.

AdrienLemaire avatar Aug 31 '21 03:08 AdrienLemaire

Hey @AdrienLemaire, I'll check if this can be implemented without too much hassle.

fkhadra avatar Aug 31 '21 05:08 fkhadra

I was wondering the exact same thing. At the moment, I have a toast for a login button with a limit={2}. When the user doesn't exist, it shows an error message. The idea is to limit the error messages to {2}, with a queueMax=0 (is it currently possible to do such thing)? Like, I don't want a queue at all.

xdebbie avatar Oct 12 '21 11:10 xdebbie

I was wondering the exact same thing. At the moment, I have a toast for a login button with a limit={2}. When the user doesn't exist, it shows an error message. The idea is to limit the error messages to {2}, with a queueMax=0 (is it currently possible to do such thing)? Like, I don't want a queue at all.

I just found a solution for that btw, I just used a custom id to avoid duplicates:

toast.error("Utilisateur non trouvé", {
     toastId: "toastAvoidsDuplicates",
});

xdebbie avatar Oct 12 '21 13:10 xdebbie

nice :)

ceconcarlsen avatar Dec 09 '21 13:12 ceconcarlsen

It would also be interesting to disable the queue completely. In my case I would prefer that a notification sent while the limit is full got lost.

vitorbertolucci avatar Jan 21 '22 21:01 vitorbertolucci

@AdrienLemaire @xdebbie @ceconcarlsen @vitorbertolucci Hi, you can find the changes you've been waiting for in the pull request above. I hope you will like my implementation.

ToastContainer now has a queueLimit property, thanks to which we can set the maximum queue length, or if we want to turn it off completely, we can give queueLimit equal to 0.

xSyki avatar Sep 25 '22 11:09 xSyki