I'm making a client management system in Laravel and ReactJS. I use Laravel for the backend and the api and ReactJS (with Context API) for the frontend of course.
I want to add a tracking timer into my application so the idea is that you can click on a button and select a client and it will start a timer, when you click on the stop button it will stop the timer and the time passed, is how much you spend working for that client.
My question is when should I send the time spend to the backend API?
My ideas:
- After the users clicked on the stop button.
- Every single minute (but with this technique the client will send a lot of requests to the backend).
NOTE: When a user refreshes the page the timer needs to continue where it left off.
Does anyone have some advice on how to do this?
CodePudding user response:
From your requirement, I guess that's fair enough when the stop button is clicked. In fact, you may capture the date-time
- once start is clicked
- once again when the stop button is clicked also find the difference between these two to identify the time consumed in your client application.
This way, refreshing the page will have no impact since these are loosely coupled.
