Foxandxss / angular-toastr

Angular port of CodeSeven/toastr.
http://foxandxss.github.io/angular-toastr/
MIT License
1.3k stars 276 forks source link

Reset/Re-run timeout on duplicate toastr #128

Open parer800 opened 9 years ago

parer800 commented 9 years ago

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}

Foxandxss commented 9 years ago

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

mmmichl commented 8 years ago

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.

Foxandxss commented 8 years ago

@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.

mmmichl commented 8 years ago

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!

Foxandxss commented 8 years ago

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 commented 8 years ago

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.

mmmichl commented 8 years ago

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