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,
|
emit: emit.call,
|
||||||
action: () async {
|
action: () async {
|
||||||
final List<DateTime> days = _getCalendarDaysForOffset(0);
|
final List<DateTime> days = _getCalendarDaysForOffset(0);
|
||||||
final List<AssignedShift> myShiftsResult = await getAssignedShifts(
|
|
||||||
GetAssignedShiftsArguments(start: days.first, end: days.last),
|
// 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(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
status: ShiftsStatus.loaded,
|
status: ShiftsStatus.loaded,
|
||||||
myShifts: myShiftsResult,
|
myShifts: myShiftsResult,
|
||||||
pendingShifts: const <PendingAssignment>[],
|
pendingShifts: pendingResult,
|
||||||
cancelledShifts: const <CancelledShift>[],
|
cancelledShifts: cancelledResult,
|
||||||
availableShifts: const <OpenShift>[],
|
availableShifts: const <OpenShift>[],
|
||||||
historyShifts: const <CompletedShift>[],
|
historyShifts: const <CompletedShift>[],
|
||||||
availableLoading: false,
|
availableLoading: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user