angular-toastr icon indicating copy to clipboard operation
angular-toastr copied to clipboard

Reset/Re-run timeout on duplicate toastr

Open parer800 opened this issue 10 years ago • 7 comments
trafficstars

Is there a way to reset the timeout of a toastr when a duplicate is denied/not shown?

Use case: when saving something an alert message is shown, and the user makes a quick change and saves again. The remaining time duration of the toastr should be reset to initial value.

So, is there currently a way of doing this? Or can there be an onDuplicate callback, or preferably an internal flag to set this: {resetTimeoutOnDuplicates: true}

parer800 avatar Sep 08 '15 06:09 parer800

There is no way of doing that. I will think about it.

Foxandxss avatar Sep 08 '15 09:09 Foxandxss

I would love have the same feature, just slightly different implemented. Rather than reset the timer and keep the toast, I would remove the old toast and add a new one. In my opinion this would make it more clear to the user that the system processed his request, but resulted in the same error.

A similar behaviour could be reproduced by invoking .clear() before displaying a toast, but this would not preserve other eventually displayed toasts.

If you are interested, I can probably put a pull request together.

mmmichl avatar Feb 02 '16 12:02 mmmichl

@mmmichl you can use .clear() to delete just 1 toast.

var toast = toastr.success(...);
toastr.clear(toast);

So you can save a reference to your toast and just remove and recreate it as needed.

Foxandxss avatar Feb 02 '16 12:02 Foxandxss

You might want to call me unreasonably picky. I am setting up a project where a lot of people will work on and I want to keep it as simple, stupid (KISS) as possible. Unfortunately I am certain this simple structure will not be obeyed in all situations by all programmers...

I would understand if this is too unreasonable to add to add to the library, I could still write a wrapper :)

BTW: solid library, I like it!

mmmichl avatar Feb 02 '16 12:02 mmmichl

Not that I am against new features, but what you need is already implemented in the library that is why I am not fond of adding yet another option for something that can be easily done.

On the other hand, the request on this issue can't be done in an easy way so that is different :/

Foxandxss avatar Feb 02 '16 12:02 Foxandxss

That being said, you just need a service to manage toasts, then you can save locally the toast shown and add a flag to the method, something like:

myService.show(data, true);

with that true you specify that if the toast is already shown, you show it again:

function show(data, reopen) {
  if (reopen && this.toast) {
    toastr.clear(this.toast);
  }
  this.toast = toastr.success(...);
}

That from the top of my head, but should do the trick.

Foxandxss avatar Feb 02 '16 12:02 Foxandxss

yap, I was thinking of something like this. Thank you for your time!

mmmichl avatar Feb 02 '16 13:02 mmmichl