Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Desync-o-tron committed Oct 2, 2024
1 parent f380a22 commit be23fb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
21 changes: 19 additions & 2 deletions lib/DOM/training_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ class TrainingSession {
);
}

bool hasEmptySets() {
for (var setsOfAnExercise in trainingData) {
for (var set in setsOfAnExercise.sets) {
bool setIsEmpty = true;
if (set.reps != null && set.reps != 0) setIsEmpty = false;
if (set.weight != null && set.weight != 0) setIsEmpty = false;
if (set.time != null && set.time != 0) setIsEmpty = false;
if (set.distance != null && set.distance != 0) setIsEmpty = false;
if (set.speed != null && set.speed != 0) setIsEmpty = false;
if (setIsEmpty) {
return true;
}
}
}
return false;
}

factory TrainingSession.fromJson(Map<String, dynamic> json) =>
_$TrainingSessionFromJson(json);
Map<String, dynamic> toJson() => _$TrainingSessionToJson(this);
Expand Down Expand Up @@ -102,8 +119,8 @@ class Set {
MassUnits? massUnits;
DistanceUnits? distanceUnits;
bool completed = false;

//todo add units. weight, distance, speed, time etc..
//if we ever add a new setMetric, then we should update TrainingSession.hasEmptySets
//todo add a units to these weight, distance, speed, time etc.. and update the gui to proccess..maybe convience functions here

Set(this.ex) {
id = DateTime.now().toIso8601String();
Expand Down
13 changes: 11 additions & 2 deletions lib/training/training_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,25 @@ class _TrainingPageState extends State<TrainingPage> {
completeLabel: 'Finish',
cancelLabel: 'Cancel',
onCancel: () {
//todo
//todo sesh.hasCompletedSets()
},
onComplete: () {
//todo check if there are still empty sets
final sesh = context.read<TrainingSessionCubit>().state;
if (sesh.hasEmptySets()) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text(
"you still have empty sets. casual. swipe 'em to remove them.")));
return;
}

sesh.isOngoing = false;
sesh.duration = DateTime.now().difference(sesh.date);
sesh.dateOfLastEdit = DateTime.now();
final histCubit = context.read<TrainingHistoryCubit>();
histCubit.addTrainingSessionToHistory(sesh);
if (sesh.trainingData.isNotEmpty) {
histCubit.addTrainingSessionToHistory(sesh);
}
context.read<TrainingSessionCubit>().reset();
context.go(routeNames.History.text);
},
Expand Down

0 comments on commit be23fb4

Please sign in to comment.