feat: load assigned, pending, and cancelled shifts in parallel for improved performance
This commit is contained in:
@@ -79,16 +79,29 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
emit: emit.call,
|
||||
action: () async {
|
||||
final List<DateTime> days = _getCalendarDaysForOffset(0);
|
||||
final List<AssignedShift> myShiftsResult = await getAssignedShifts(
|
||||
|
||||
// Load assigned, pending, and cancelled shifts in parallel.
|
||||
final List<Object> results = await Future.wait(<Future<Object>>[
|
||||
getAssignedShifts(
|
||||
GetAssignedShiftsArguments(start: days.first, end: days.last),
|
||||
);
|
||||
),
|
||||
getPendingAssignments(),
|
||||
getCancelledShifts(),
|
||||
]);
|
||||
|
||||
final List<AssignedShift> myShiftsResult =
|
||||
results[0] as List<AssignedShift>;
|
||||
final List<PendingAssignment> pendingResult =
|
||||
results[1] as List<PendingAssignment>;
|
||||
final List<CancelledShift> cancelledResult =
|
||||
results[2] as List<CancelledShift>;
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ShiftsStatus.loaded,
|
||||
myShifts: myShiftsResult,
|
||||
pendingShifts: const <PendingAssignment>[],
|
||||
cancelledShifts: const <CancelledShift>[],
|
||||
pendingShifts: pendingResult,
|
||||
cancelledShifts: cancelledResult,
|
||||
availableShifts: const <OpenShift>[],
|
||||
historyShifts: const <CompletedShift>[],
|
||||
availableLoading: false,
|
||||
|
||||
Reference in New Issue
Block a user