@@ -22,14 +22,20 @@ export default function TrackWorkout({ params, template } : { params?: { workout
22
22
const [ modals , setModals ] = useState < Modal > ( )
23
23
const [ exercises , setExercises ] = useState < ExerciseData [ ] > ( [ ] )
24
24
const [ previousStats , setPreviousStats ] = useState < PreviousStats > ( )
25
-
25
+
26
26
useEffect ( ( ) => {
27
27
apiWithAuth ( token ) . get ( 'exercises' ) . then ( response => {
28
28
setExercises ( response . data ) ;
29
29
} ) . catch ( error => {
30
30
console . log ( error ) ;
31
31
} ) ;
32
32
33
+ const initial : Workout = {
34
+ user : user ?. sub ! ,
35
+ status : "IN_PROGRESS" ,
36
+ exercises : [ ]
37
+ }
38
+
33
39
const workoutStorage = localStorage . getItem ( 'workoutDraft' ) ;
34
40
35
41
if ( params ?. workoutid ) {
@@ -54,25 +60,21 @@ export default function TrackWorkout({ params, template } : { params?: { workout
54
60
} ) ;
55
61
} else if ( workoutStorage && workoutStorage !== "undefined" ) {
56
62
const workoutStorageParsed : Workout = JSON . parse ( workoutStorage ! ) ;
57
- if ( workoutStorageParsed . status === "IN_PROGRESS" ) {
63
+
64
+ if ( workoutStorageParsed . status === "IN_PROGRESS" && workoutStorageParsed . user == user . sub ) {
58
65
setWorkout ( JSON . parse ( workoutStorage ) ) ;
66
+ } else {
67
+ setWorkout ( initial ) ;
59
68
}
60
69
} else {
61
- const initial : Workout = {
62
- user : user ?. sub ! ,
63
- status : "IN_PROGRESS" ,
64
- exercises : [ ]
65
- }
66
70
setWorkout ( initial ) ;
67
71
}
68
72
69
73
} , [ params ?. workoutid , template , token , user ?. sub ] ) ;
70
74
71
75
useEffect ( ( ) => {
72
76
if ( workout ) {
73
- if ( ! params ?. workoutid ) {
74
- localStorage . setItem ( 'workoutDraft' , JSON . stringify ( workout ) ) ;
75
- }
77
+ localStorage . setItem ( 'workoutDraft' , JSON . stringify ( workout ) ) ;
76
78
}
77
79
} , [ workout , params ?. workoutid ] ) ;
78
80
@@ -244,8 +246,8 @@ export default function TrackWorkout({ params, template } : { params?: { workout
244
246
</ table >
245
247
< div className = "text-xs mt-4 mb-2 py-3 px-2 rounded-md bg-white/20 block text-center" onClick = { ( e ) => addSet ( indexExercise ) } > Adicionar set</ div >
246
248
< div className = "flex justify-between gap-2 text-center" >
247
- < div className = "flex-1 text-xs py-3 px-2 rounded-md bg-white/20" onClick = { ( e ) => { getPreviousStats ( workout . user , exercise . id , 'previousSets' ) } } > Estatísticas anteriores</ div >
248
- < div className = "flex-1 text-xs py-3 px-2 rounded-md bg-white/20" onClick = { ( e ) => { getPreviousStats ( workout . user , exercise . id , '1RM' ) } } > One Rep Max</ div >
249
+ < div className = "flex-1 text-xs py-3 px-2 rounded-md bg-white/20" onClick = { ( e ) => { getPreviousStats ( user . sub , exercise . id , 'previousSets' ) } } > Estatísticas anteriores</ div >
250
+ < div className = "flex-1 text-xs py-3 px-2 rounded-md bg-white/20" onClick = { ( e ) => { getPreviousStats ( user . sub , exercise . id , '1RM' ) } } > One Rep Max</ div >
249
251
</ div >
250
252
</ div >
251
253
)
0 commit comments