Skip to content

Commit

Permalink
Do not duplicate workouts while pushing to state
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryashutov committed Nov 23, 2023
1 parent 542988b commit 986f4dd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/models/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const ActivityModel = types
.actions((self) => ({
pushWorkouts: (workouts: Workout[]) => {
for (const workout of workouts) {
const existingWorkout = self.workouts.find((w) => w.id === workout.id);
if (existingWorkout) {
continue;
}
self.workouts.push(workout);
if (self.workouts.length > WORKOUTS_HISTORY_TO_KEEP) {
self.workouts.shift();
Expand Down

0 comments on commit 986f4dd

Please sign in to comment.