In this Bubble tutorial video, I'm going to demonstrate how you can add in a loading animation while your Bubble app makes the API call to the OpenAI API. This is a great bit of UI and UX improvement that you can make to your app, because sometimes users just get a bit confused when they click a button and it appears like nothing happens. And yes, Bubble, if you're doing a client side workflow, yes, Bubble puts a slowly bug on across the top of the screen, but you can improve upon that so that your users know that they're getting something good and that they need to wait for it, which is all important when you're using OpenAI with Bubble.
Leveraging the Power of Lottie Animation
I'm going to demonstrate in this tutorial how to do that with Lottie animations. Lottiefiles has become a popular format for animations on the web because they're lightweight. They're basically JSON files, and they scale quite nicely too. So they've got a number of advantages over GIFs or other image animation files.
Adding a Lottie animation to your Bubble App
So to add in a Lottie animation, I need to add in a plugin. And I'm just going to pick one of these. This one's got a lot of users. Let's try that one and add in Lottie. Let's just make this 300 by 300. Obviously, you adapt to the right size. And then a Lottie file. Now, if you want complete control over where you're hosting it, you can download the Lottie file. You can upload it to your Bubble storage. But in this example, I'm just going to pick one of these. And I am going to link directly to it into one of my workspaces in Lottie. I think I need to click this one here of JSON.
So then I paste that in there is the dynamic link, and I'm going to preview my app to see if it loads in the Lottie animation correctly. Brilliant. Yes, it does. So how do I get it to show during my API call and no other time? So first of all, I've made sure that wherever I'm displaying my results, I have this unticked, the element is visible on page load, and I tick collapse when hidden. And then on my Lottie element, now that I've added that in, I'm going to also say it is not visible on page load and it's collapsed when hidden. And then I need to add just a couple of steps or maybe three steps to my submit button.
Triggering the Lottie Animation During OpenAI API Calls
So the first thing I'm going to do when the button is clicked is show my lot in animation. I'm going to show that first. This is where the app makes a call to the OpenAI API. And so this is actually where the waiting occurs. And then in this case, I'm using a custom state. I'm saving it as a custom state in order to display the results on my page. And so I'm going to add into here, hide, Lottie, because I know that it's completed the wait from OpenAI here. And then I'm going to show, in this case, I'm using a multiline input. This just happens to be the element I'm using to display the reply from OpenAI.
So let's preview. I'll go to Twitter again, and I'll say, What are the limitations of Bubble.io? Yeah. I see my animation there. I'm also getting the Bubble loading bar across the top, and then the animation gives way to the results. There you have it. That is how you can use a loading animation to improve the UI in your Bubble app. And if you're learning Bubble, you need to check out our website, planetnocode.com, where we've got hundreds of Bubble tutorial videos, some which you cannot find on YouTube. We're hoping to create the best resource for learning Bubble out there.