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

Feature request: detect if a notification already exists #3

Closed
ajmeese7 opened this issue Aug 27, 2019 · 4 comments
Closed

Feature request: detect if a notification already exists #3

ajmeese7 opened this issue Aug 27, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@ajmeese7
Copy link
Contributor

It would be a really useful feature if when a new notification is opened there was an option to detect if one is already present and to decide what action to take if there is. For example, you could choose to still show the new notification (default) or to close the old one as as it closes bring in the new notification.

Currently in my project if a user clicks buttons too quickly they will have more than one notification show at once and it is not attractive with how they are styled in my app. If you do not plan on working on this I will see if I can brew up my own solution in a few months when I have time.

@Glagan
Copy link
Owner

Glagan commented Aug 27, 2019

Hi, there is a function disableButtons() than you can call inside the callbacks of your buttons.
You can do it like that:

{
  buttons: {
    value: "Close",
    onClick: (notification) => {
      notification.disableButtons();
      // Do anything you want :)
      notification.close(); // Or notification.remove() if you want the notification to close immediately
    }
  }
}

The functions you ask for seems easy enough to do though, so I can make it.
Does the option to only have 1 notification is global or per notification, so if the option is enabled there will always be only one notification, or if a notification with the parameter is displayed it close all other notifications ?

Edit: I can also make an option to automatically disable buttons if a button is clicked, before calling the callback.

@Glagan Glagan added the enhancement New feature or request label Aug 27, 2019
@ajmeese7
Copy link
Contributor Author

I could see both options making sense. It would be nice if both could be implemented, but if not then I'd say per notification. It would make the code a lot cleaner if I didn't have to use a method like notification.close() each time I wanted to add one to the screen.

Can you go into a bit more detail about the disableButtons function? It seems like you can only use it within the buttons that are a part of a notification, which doesn't really help in this use case.

@Glagan
Copy link
Owner

Glagan commented Aug 27, 2019

I will add the maxNotifications and closeAllOnDisplay options then (maybe not exactly these names).

The disableButtons function just loop trough each displayed button and add the disabled state, so they can't be clicked.
You can call it from anywhere, any events, on button click and in general if you have a SimpleNotification object.

// SimpleNotification.[type] return a SimpleNotification object
let n = SimpleNotification.info({
  title: "Title",
  buttons: {
    value: "Test",
    onClick: n => {
      // Inside buttons
      n.disableButtons();
    }
  }
}, {
  events: {
    onDeath: n => {
      // Inside events
      n.disableButtons();
    }
  }
});
// Basically when you have a SimpleNotification object
n.disableButtons();

@ajmeese7
Copy link
Contributor Author

Closing due to feature implementation. Documented the new features in #4

Glagan added a commit that referenced this issue Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants