Notifications are alerts which get sent to your app users. In this Bubble tutorial, we'll learn how we can set up notifications in our Bubble app.
Notifications might seem like a small thing, but they play a large role in engaging your users. You can send notifications to a user when they are assigned a task or someone mentions them etc.
If you'd like to send notifications to your app users, you don't need any plugin. The set-up is simple and will take less than 30 minutes.
Database setup in Bubble
We'll begin by creating a new data type to store all the notifications.
This data type will store the body of the notification, the associated person and whether it has been read.
Create a new data type called Notifications.
Content — to display the notifications text body.
Name — just a heading to denote the ‘notification type’ for e.g A new task added or a new reminder added. This can be custom or pre-filled and can be left out as well.
Read — to denote whether the notification has been read by the recipient or not.
User — to save the User who has been assigned this notification.
You can customize these fields and add more fields if required.
Creating a new notification
Depending upon our application, we'll create a workflow to create a new notification.
Once you’ve created a new notification entry, all that is left is for us to display these notifications.
Displaying the notifications
You can add a bell icon or any button that you feel a user should click on to view their notifications. I’ve added a small bell icon in my app where I want the users to click to view their notifications.
I then added a Group Focus to display the notifications. Once you’ve set up the design of the Group Focus, add a Repeating Group inside it.
The type of content should be Notifications and the data source can be left blank. But how will it find the relevant notifications if the data source is blank? We’ll add the data source in the conditional statements.
Why put the data source in conditional statements?
The reasoning is that Bubble will load the Repeating Group content only when the condition is satisfied. And not on page load.
We don't want to pre-load the notifications. We can load them when a user clicks on the notification icon. This will improve page load speed and response time slightly if you have multiple repeating groups on the page.
This is a good example of using conditional statements in Bubble to improve your app performance.
This setup will ensure that only the unread notifications are displayed in the Repeating Group.
You can then add the elements in the Repeating Group to display all the information. Namely the text, number, date etc.
Create a trigger to display the Group Focus when the Notifications icon is clicked.
Marking the notifications as 'Read'
Once you have the Group Focus and the Repeating Group setup, you would like the notifications to not be displayed again once they’ve been read once.
Add a new text element or a checkbox that the user can click to mark all the notifications as read. I’ve added a text element ‘Mark all as read’. When the user clicks on this, a workflow is triggered.
This updates the ‘Read’ field of all the current notifications to Yes. And if you recall, we had set a condition for the Repeating Group, to only display notifications where the ‘Read’ field is No.
As a result, all the notifications are hidden from the Repeating Group. You can then add another step to hide the Group Focus or whatever way you’d like your app to behave.
If you enjoyed this article, share it with your friends and colleagues!