Skip to content

Commit d2eb115

Browse files
committed
feat(schedule-overlap): implement schedule overlap checks in ScheduleDateTimeCubit and SchedulePlaceMovingTimeCubit
1 parent e68a8b5 commit d2eb115

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/presentation/schedule_create/schedule_date_time/cubit/schedule_date_time_cubit.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class ScheduleDateTimeCubit extends Cubit<ScheduleDateTimeState> {
3636
scheduleDate: scheduleDateTimeState.scheduleDate,
3737
scheduleTime: scheduleDateTimeState.scheduleTime,
3838
));
39+
40+
// Check for schedule overlap if both date and time are valid
41+
if (scheduleDateTimeState.scheduleDate.isValid &&
42+
scheduleDateTimeState.scheduleTime.isValid) {
43+
// Load adjacent schedules first, then check overlap
44+
_loadAdjacentSchedules(scheduleDateTimeState.scheduleDate.value!)
45+
.then((_) => checkScheduleOverlap());
46+
}
47+
3948
scheduleFormBloc.add(ScheduleFormValidated(isValid: state.isValid));
4049
}
4150

lib/presentation/schedule_create/schedule_place_moving_time.dart/cubit/schedule_place_moving_time_cubit.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,37 @@ class SchedulePlaceMovingTimeCubit extends Cubit<SchedulePlaceMovingTimeState> {
2020
final schedulePlaceMovingTimeState =
2121
SchedulePlaceMovingTimeState.fromScheduleFormState(
2222
scheduleFormBloc.state);
23+
24+
// Check for overlap using current form state values
25+
final formState = scheduleFormBloc.state;
26+
final maxAvailableTime = formState.maxAvailableTime;
27+
final moveTime = schedulePlaceMovingTimeState.moveTime.value;
28+
29+
Duration? overlapDuration;
30+
bool isOverlapping = false;
31+
32+
if (maxAvailableTime != null && formState.scheduleTime != null) {
33+
// Calculate new time left
34+
final newTimeLeft = maxAvailableTime - moveTime;
35+
final minutesDifference = newTimeLeft.inMinutes;
36+
37+
if (minutesDifference <= 0) {
38+
// Already overlapping - show as error
39+
overlapDuration = newTimeLeft.abs();
40+
isOverlapping = true;
41+
} else if (minutesDifference < scheduleOverlapWarningThresholdMinutes) {
42+
// Show warning if there's still time left
43+
overlapDuration = newTimeLeft;
44+
isOverlapping = false;
45+
}
46+
}
47+
2348
emit(state.copyWith(
2449
placeName: schedulePlaceMovingTimeState.placeName,
2550
moveTime: schedulePlaceMovingTimeState.moveTime,
51+
overlapDuration: overlapDuration,
52+
isOverlapping: isOverlapping,
53+
clearOverlap: overlapDuration == null,
2654
));
2755
scheduleFormBloc.add(ScheduleFormValidated(isValid: state.isValid));
2856
}

0 commit comments

Comments
 (0)