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

Add ids and events to notifications #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jkeen
Copy link
Contributor

@jkeen jkeen commented May 7, 2023

I wanted to be able to mark a notification record as read on the backend when a user closed a (frontile) notification on the frontend, and this PR opens up that possibility.

  • Adds an id attribute to the notification object in frontile, and that id is output as a data-notification-id attribute on the Notification component.
  • When a notification is added or removed on the frontend, an event is fired on the manager object, allowing consumers to tie into that.

An example of this in use:

...
  @service cable;
  @service notifications

  subscribeToUpdates(user) {
    this.subscribeToNotificationsChannel(user);

    this.notifications.manager.on('remove', this.notificationRead.bind(this));
  }

  notificationRead(notification) {
    if (this.subscriptions.notificationsChannel) {
      this.subscriptions.notificationsChannel.perform('mark_as_read', {
        ids: [notification.id],
      });
    }
  }
...

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

Successfully merging this pull request may close these issues.

1 participant