I have a Habit App and I want to add streaks to my habits. Like Snapchat or like Duolingo. If the user completes the habit +1 on the streak. If he does not the streak goes to zero.
The problem is: checking the status of the streak.
Currently I am saving the “completed” dates as a list of texts (date:formatted as 24/07/2023) to each habit.
I am not sure how I can find out how long the current streak went - and it becomes even more complicated as I have different intervals (Daily, Weekly, Monthly, Yearly, Custom: user selects weekdays)
Maybe a possibility would be to just check the streak on the frontend (so have nothing in the database)?
Would be more than thankful for any hints on how to achieve this…
The app also contains a calendar and it comes in handy to check if the task should be displayed that day. I am storing every date so that the user can go back in the calendar to see when he did what (probably not even that important)
To save the start and end date is an idea.
What about other cycles (weekly and most of all Custom: where the user selects different days of the week)? They are saved in the database as numbers (for :extract day)
The app also contains a calendar and it comes in handy to check if the task should be displayed that day. I am storing every date so that the user can go back in the calendar to see when he did what (probably not even that important)
So just store the previous streaks somewhere (probably as a separate datatype would be best).
What about other cycles (weekly and most of all Custom: where the user selects different days of the week)? They are saved in the database as numbers (for :extract day)
It depends what you mean exactly, but the same concept should apply regardless of the timeframe.
—> After a user completes their first action, cancel, then reschedule an APi WF to reset the streak tomorrow at 23:59pm. This way, the user basically pushes back the “resetting” of their streak as long as they keep working out every day.