diff --git a/lib/providers/routines.dart b/lib/providers/routines.dart index 97b4c3a63..d726c9c3b 100644 --- a/lib/providers/routines.dart +++ b/lib/providers/routines.dart @@ -462,10 +462,33 @@ class RoutinesProvider with ChangeNotifier { baseProvider.makeUrl(_slotsUrlPath), ); final set = Slot.fromJson(data); + + for (final routine in _routines) { + for (final day in routine.days) { + if (day.id == slot.day) { + day.slots.add(set); + break; + } + } + } + notifyListeners(); return set; } + Future deleteSlot(int slotId) async { + final data = await baseProvider.deleteRequest(_slotsUrlPath, slotId); + + for (final routine in _routines) { + for (final day in routine.days) { + day.slots.removeWhere((s) => s.id == slotId); + break; + } + } + + notifyListeners(); + } + Future editSlot(Slot workoutSet) async { await baseProvider.patch( workoutSet.toJson(), @@ -583,17 +606,6 @@ class RoutinesProvider with ChangeNotifier { notifyListeners(); } - Future deleteSlot(int slotId) async { - await baseProvider.deleteRequest(_slotsUrlPath, slotId); - - for (final workout in _routines) { - for (final day in workout.days) { - day.slots.removeWhere((slot) => slot.id == slotId); - } - } - notifyListeners(); - } - /* * Setting */ diff --git a/test/workout/repetition_unit_form_widget_test.mocks.dart b/test/workout/repetition_unit_form_widget_test.mocks.dart index 66113dc07..b10bf128d 100644 --- a/test/workout/repetition_unit_form_widget_test.mocks.dart +++ b/test/workout/repetition_unit_form_widget_test.mocks.dart @@ -460,6 +460,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { )), ) as _i13.Future<_i7.Slot>); + @override + _i13.Future deleteSlot(int? slotId) => (super.noSuchMethod( + Invocation.method( + #deleteSlot, + [slotId], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override _i13.Future editSlot(_i7.Slot? workoutSet) => (super.noSuchMethod( Invocation.method( @@ -480,6 +490,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); + @override + _i13.Future deleteSlotEntry(int? id) => (super.noSuchMethod( + Invocation.method( + #deleteSlotEntry, + [id], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override String getConfigUrl(_i9.ConfigType? type) => (super.noSuchMethod( Invocation.method( @@ -563,7 +583,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { ) as _i13.Future); @override - _i13.Future handleConfig( + _i13.Future handleConfig( _i9.SlotEntry? entry, String? input, _i9.ConfigType? type, @@ -577,24 +597,15 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { type, ], ), - returnValue: _i13.Future.value(), - ) as _i13.Future); - - @override - _i13.Future fetchComputedSettings(_i7.Slot? workoutSet) => (super.noSuchMethod( - Invocation.method( - #fetchComputedSettings, - [workoutSet], - ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); @override - _i13.Future deleteSlot(int? setId) => (super.noSuchMethod( + _i13.Future fetchComputedSettings(_i7.Slot? slot) => (super.noSuchMethod( Invocation.method( - #deleteSet, - [setId], + #fetchComputedSettings, + [slot], ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), diff --git a/test/workout/workout_day_form_test.mocks.dart b/test/workout/workout_day_form_test.mocks.dart index 2aace8eb3..791057901 100644 --- a/test/workout/workout_day_form_test.mocks.dart +++ b/test/workout/workout_day_form_test.mocks.dart @@ -460,6 +460,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { )), ) as _i13.Future<_i7.Slot>); + @override + _i13.Future deleteSlot(int? slotId) => (super.noSuchMethod( + Invocation.method( + #deleteSlot, + [slotId], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override _i13.Future editSlot(_i7.Slot? workoutSet) => (super.noSuchMethod( Invocation.method( @@ -480,6 +490,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); + @override + _i13.Future deleteSlotEntry(int? id) => (super.noSuchMethod( + Invocation.method( + #deleteSlotEntry, + [id], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override String getConfigUrl(_i9.ConfigType? type) => (super.noSuchMethod( Invocation.method( @@ -563,7 +583,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { ) as _i13.Future); @override - _i13.Future handleConfig( + _i13.Future handleConfig( _i9.SlotEntry? entry, String? input, _i9.ConfigType? type, @@ -577,24 +597,15 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { type, ], ), - returnValue: _i13.Future.value(), - ) as _i13.Future); - - @override - _i13.Future fetchComputedSettings(_i7.Slot? workoutSet) => (super.noSuchMethod( - Invocation.method( - #fetchComputedSettings, - [workoutSet], - ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); @override - _i13.Future deleteSlot(int? setId) => (super.noSuchMethod( + _i13.Future fetchComputedSettings(_i7.Slot? slot) => (super.noSuchMethod( Invocation.method( - #deleteSet, - [setId], + #fetchComputedSettings, + [slot], ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), diff --git a/test/workout/workout_form_test.mocks.dart b/test/workout/workout_form_test.mocks.dart index cb58ebf1d..03b4c8edc 100644 --- a/test/workout/workout_form_test.mocks.dart +++ b/test/workout/workout_form_test.mocks.dart @@ -460,6 +460,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { )), ) as _i13.Future<_i7.Slot>); + @override + _i13.Future deleteSlot(int? slotId) => (super.noSuchMethod( + Invocation.method( + #deleteSlot, + [slotId], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override _i13.Future editSlot(_i7.Slot? workoutSet) => (super.noSuchMethod( Invocation.method( @@ -480,6 +490,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); + @override + _i13.Future deleteSlotEntry(int? id) => (super.noSuchMethod( + Invocation.method( + #deleteSlotEntry, + [id], + ), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value(), + ) as _i13.Future); + @override String getConfigUrl(_i9.ConfigType? type) => (super.noSuchMethod( Invocation.method( @@ -563,7 +583,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { ) as _i13.Future); @override - _i13.Future handleConfig( + _i13.Future handleConfig( _i9.SlotEntry? entry, String? input, _i9.ConfigType? type, @@ -577,24 +597,15 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider { type, ], ), - returnValue: _i13.Future.value(), - ) as _i13.Future); - - @override - _i13.Future fetchComputedSettings(_i7.Slot? workoutSet) => (super.noSuchMethod( - Invocation.method( - #fetchComputedSettings, - [workoutSet], - ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), ) as _i13.Future); @override - _i13.Future deleteSlot(int? setId) => (super.noSuchMethod( + _i13.Future fetchComputedSettings(_i7.Slot? slot) => (super.noSuchMethod( Invocation.method( - #deleteSet, - [setId], + #fetchComputedSettings, + [slot], ), returnValue: _i13.Future.value(), returnValueForMissingStub: _i13.Future.value(), diff --git a/test/workout/workout_set_form_test.mocks.dart b/test/workout/workout_set_form_test.mocks.dart index 8a209adc9..1a59d3f87 100644 --- a/test/workout/workout_set_form_test.mocks.dart +++ b/test/workout/workout_set_form_test.mocks.dart @@ -1181,6 +1181,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i23.RoutinesProvider { )), ) as _i21.Future<_i15.Slot>); + @override + _i21.Future deleteSlot(int? slotId) => (super.noSuchMethod( + Invocation.method( + #deleteSlot, + [slotId], + ), + returnValue: _i21.Future.value(), + returnValueForMissingStub: _i21.Future.value(), + ) as _i21.Future); + @override _i21.Future editSlot(_i15.Slot? workoutSet) => (super.noSuchMethod( Invocation.method( @@ -1201,6 +1211,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i23.RoutinesProvider { returnValueForMissingStub: _i21.Future.value(), ) as _i21.Future); + @override + _i21.Future deleteSlotEntry(int? id) => (super.noSuchMethod( + Invocation.method( + #deleteSlotEntry, + [id], + ), + returnValue: _i21.Future.value(), + returnValueForMissingStub: _i21.Future.value(), + ) as _i21.Future); + @override String getConfigUrl(_i17.ConfigType? type) => (super.noSuchMethod( Invocation.method( @@ -1284,7 +1304,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i23.RoutinesProvider { ) as _i21.Future); @override - _i21.Future handleConfig( + _i21.Future handleConfig( _i17.SlotEntry? entry, String? input, _i17.ConfigType? type, @@ -1298,24 +1318,15 @@ class MockRoutinesProvider extends _i1.Mock implements _i23.RoutinesProvider { type, ], ), - returnValue: _i21.Future.value(), - ) as _i21.Future); - - @override - _i21.Future fetchComputedSettings(_i15.Slot? workoutSet) => (super.noSuchMethod( - Invocation.method( - #fetchComputedSettings, - [workoutSet], - ), returnValue: _i21.Future.value(), returnValueForMissingStub: _i21.Future.value(), ) as _i21.Future); @override - _i21.Future deleteSlot(int? setId) => (super.noSuchMethod( + _i21.Future fetchComputedSettings(_i15.Slot? slot) => (super.noSuchMethod( Invocation.method( - #deleteSet, - [setId], + #fetchComputedSettings, + [slot], ), returnValue: _i21.Future.value(), returnValueForMissingStub: _i21.Future.value(),