Restart the rest timer when its set is saved for the first time

This commit is contained in:
Roland Geider
2026-10-25 21:36:21 +01:00
parent 6fdc857381
commit 58cd06bb4c
2 changed files with 42 additions and 0 deletions

View File

@@ -450,6 +450,8 @@ class GymStateNotifier extends _$GymStateNotifier {
/// is kept on the slot page so revisiting the page pre-fills the form with
/// the saved values and saving updates the row instead of inserting a
/// duplicate.
///
/// The first save also (re)starts the rest timer that follows the set.
void markSlotPageAsDone(String uuid, {required bool isDone, Log? log}) {
final slotPage = state.getSlotPageByUUID(uuid);
if (slotPage == null) {
@@ -459,6 +461,12 @@ class GymStateNotifier extends _$GymStateNotifier {
_updateSlotPage(uuid, slotPage.copyWith(logDone: isDone, loggedEntry: log));
_logger.fine('Set logDone=$isDone for slot page UUID $uuid');
// Scrolling past the timer (e.g. "jump to") already started it
final timerPage = state.getSlotEntryPageByIndex(slotPage.pageIndex + 1);
if (slotPage.loggedEntry == null && timerPage?.type == SlotPageType.timer) {
_updateSlotPage(timerPage!.uuid, timerPage.copyWith(timerStartedAt: clock.now()));
}
}
void replaceExercises(

View File

@@ -162,6 +162,40 @@ void main() {
DateTime(2024, 5, 2, 12),
);
});
test('Saving a set restarts the following timer, editing it does not', () {
// Arrange: the timer was started by scrolling past it
final logPage = notifier.state.pages[1].slotPages[1];
final timerPage = notifier.state.pages[1].slotPages[2];
expect(logPage.type, SlotPageType.log);
expect(timerPage.type, SlotPageType.timer);
withClock(Clock.fixed(DateTime(2024, 5, 2, 12)), () {
notifier.startTimerIfNeeded(timerPage.uuid);
});
final log = Log.fromSetConfigData(logPage.setConfigData!, routineId: 1, iteration: 1);
// Act: the set is saved
withClock(Clock.fixed(DateTime(2024, 5, 2, 12, 10)), () {
notifier.markSlotPageAsDone(logPage.uuid, isDone: true, log: log);
});
// Assert
expect(
notifier.state.getSlotPageByUUID(timerPage.uuid)!.timerStartedAt,
DateTime(2024, 5, 2, 12, 10),
);
// Act: correcting the saved set keeps the running timer
withClock(Clock.fixed(DateTime(2024, 5, 2, 12, 11)), () {
notifier.markSlotPageAsDone(logPage.uuid, isDone: true, log: log);
});
// Assert
expect(
notifier.state.getSlotPageByUUID(timerPage.uuid)!.timerStartedAt,
DateTime(2024, 5, 2, 12, 10),
);
});
});
group('GymStateNotifier.recalculateIndices', () {