diff --git a/apps/mobile/NEXT_SPRINT_TASKS.md b/apps/mobile/NEXT_SPRINT_TASKS.md index cdc791b6..ff397940 100644 --- a/apps/mobile/NEXT_SPRINT_TASKS.md +++ b/apps/mobile/NEXT_SPRINT_TASKS.md @@ -19,3 +19,4 @@ - ` final String status;` in `OrderItem` make it an enum. - /// Date of the shift (ISO format). final String date; make this in the DateTime format instead of string. +- in `view_orders_cubit.dart` combine the logic of `_calculateUpNextCount ` and `_calculateTodayCount` into a single function that calculates both counts together to avoid redundant filtering of orders. diff --git a/apps/mobile/packages/features/client/view_orders/lib/src/presentation/blocs/view_orders_cubit.dart b/apps/mobile/packages/features/client/view_orders/lib/src/presentation/blocs/view_orders_cubit.dart index 1bb51869..a413e494 100644 --- a/apps/mobile/packages/features/client/view_orders/lib/src/presentation/blocs/view_orders_cubit.dart +++ b/apps/mobile/packages/features/client/view_orders/lib/src/presentation/blocs/view_orders_cubit.dart @@ -252,13 +252,19 @@ class ViewOrdersCubit extends Cubit { } int _calculateCategoryCount(String category) { + if (state.selectedDate == null) return 0; + + final String selectedDateStr = DateFormat( + 'yyyy-MM-dd', + ).format(state.selectedDate!); + if (category == 'active') { return state.orders - .where((OrderItem s) => s.status == 'IN_PROGRESS') + .where((OrderItem s) => s.date == selectedDateStr && s.status == 'IN_PROGRESS') .length; } else if (category == 'completed') { return state.orders - .where((OrderItem s) => s.status == 'COMPLETED') + .where((OrderItem s) => s.date == selectedDateStr && s.status == 'COMPLETED') .length; } return 0;