Calculation dynamic time difference between 2 rows for specific user

I’m currently building a sleep tracking app. I need to be able to calculate the window of time between the end of the last nap, and the beginning of the next nap.

Ex.
Nap 1: Ended at 9am
Nap 2: Started at 10:30am
Wake Window: 1h30m

The issue I’m having is the database structure. All of my sleep records are in 1 large table. When someone submits a new nap, I need to be able to find the most recent nap for that specific user, calculate the wake window, and then remember that specific math, because then if they go back and change the entry, the original wake window should update.

I’ve tried using a rollup and getting the most recent nap for that user, but the problem I can see is that, when someone submits the nap, that nap itself is the most recent now, so it will just be stuck in a loop.

Have a video here

Thank you!