-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
753f2b2
commit 0a29859
Showing
4 changed files
with
60 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,23 @@ | ||
/* eslint-disable svelte/no-ignored-unsubscribe */ | ||
import { type Writable, writable } from "svelte/store"; | ||
import { type Writable } from "svelte/store"; | ||
import { persisted } from "svelte-persisted-store"; | ||
|
||
let ls: Storage | undefined; | ||
if (typeof window !== "undefined") { | ||
ls = localStorage; | ||
} | ||
|
||
export const workoutBeingPerformed: Writable<WorkoutBeingPerformed | null> = writable( | ||
JSON.parse(ls?.getItem("workoutBeingPerformed") || "null") | ||
); | ||
export const exercisesPerformed: Writable<WorkoutExerciseWithoutSetNumbers[] | null> = writable( | ||
JSON.parse(ls?.getItem("exercisesPerformed") || "null") | ||
export const workoutBeingPerformed: Writable<WorkoutBeingPerformed | null> = persisted( | ||
"workoutBeingPerformed", | ||
null | ||
); | ||
export const allExercisesSetsCompleted: Writable<boolean[][]> = writable( | ||
JSON.parse(ls?.getItem("allExercisesSetsCompleted") || "[]") | ||
export const exercisesPerformed: Writable<WorkoutExerciseWithoutSetNumbers[] | null> = persisted( | ||
"exercisesPerformed", | ||
null | ||
); | ||
export const workloadData: Writable<Workout["muscleGroupWorkloads"]> = writable( | ||
JSON.parse(ls?.getItem("muscleGroupWorkloads") || "{}") | ||
export const allExercisesSetsCompleted: Writable<boolean[][]> = persisted( | ||
"allExercisesSetsCompleted", | ||
[] | ||
); | ||
export const sorenessData: Writable<Workout["muscleSorenessToNextWorkout"]> = writable( | ||
JSON.parse(ls?.getItem("muscleSorenessToNextWorkout") || "{}") | ||
export const workloadData: Writable<Workout["muscleGroupWorkloads"]> = persisted( | ||
"muscleGroupWorkloads", | ||
{} | ||
); | ||
|
||
workoutBeingPerformed.subscribe((val) => ls?.setItem("workoutBeingPerformed", JSON.stringify(val))); | ||
exercisesPerformed.subscribe((exercises) => { | ||
ls?.setItem("exercisesPerformed", JSON.stringify(exercises)); | ||
// Sync with workoutBeingPerformed | ||
workoutBeingPerformed.update((workout) => { | ||
if (exercises && workout) { | ||
workout.exercisesPerformed = exercises; | ||
} | ||
return workout; | ||
}); | ||
}); | ||
allExercisesSetsCompleted.subscribe( | ||
(val) => ls?.setItem("allExercisesSetsCompleted", JSON.stringify(val)) | ||
export const sorenessData: Writable<Workout["muscleSorenessToNextWorkout"]> = persisted( | ||
"muscleSorenessToNextWorkout", | ||
{} | ||
); | ||
workloadData.subscribe((val) => ls?.setItem("workloadData", JSON.stringify(val))); | ||
sorenessData.subscribe((val) => ls?.setItem("sorenessData", JSON.stringify(val))); |