diff --git a/packages/registration_delivery/lib/blocs/household_overview/household_overview.dart b/packages/registration_delivery/lib/blocs/household_overview/household_overview.dart index f9cd1f8b2..b3aa1f396 100644 --- a/packages/registration_delivery/lib/blocs/household_overview/household_overview.dart +++ b/packages/registration_delivery/lib/blocs/household_overview/household_overview.dart @@ -14,6 +14,7 @@ import '../../models/entities/referral.dart'; import '../../models/entities/side_effect.dart'; import '../../models/entities/task.dart'; import '../../utils/typedefs.dart'; +import '../../utils/utils.dart'; import '../search_households/search_households.dart'; part 'household_overview.freezed.dart'; @@ -173,14 +174,11 @@ class HouseholdOverviewBloc } // Search for tasks associated with project beneficiaries. - final tasks = await taskDataRepository.search(TaskSearchModel( + var tasks = await taskDataRepository.search(TaskSearchModel( projectBeneficiaryClientReferenceId: projectBeneficiaries.map((e) => e.clientReferenceId).toList())); - tasks.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + tasks = sortTasks(tasks); // Search for adverse events associated with tasks. final sideEffects = diff --git a/packages/registration_delivery/lib/blocs/search_households/household_global_seach.dart b/packages/registration_delivery/lib/blocs/search_households/household_global_seach.dart index 806af9f42..2140e100b 100644 --- a/packages/registration_delivery/lib/blocs/search_households/household_global_seach.dart +++ b/packages/registration_delivery/lib/blocs/search_households/household_global_seach.dart @@ -102,10 +102,7 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; @@ -171,10 +168,7 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; @@ -224,10 +218,8 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); + sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; diff --git a/packages/registration_delivery/lib/blocs/search_households/individual_global_search.dart b/packages/registration_delivery/lib/blocs/search_households/individual_global_search.dart index 097a66eee..2e42aca0b 100644 --- a/packages/registration_delivery/lib/blocs/search_households/individual_global_search.dart +++ b/packages/registration_delivery/lib/blocs/search_households/individual_global_search.dart @@ -104,10 +104,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); + sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; @@ -171,10 +169,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); + sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; @@ -223,10 +219,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc { projectBeneficiariesList, taskList, sideEffectsList, referralsList); taskList = tasksRelated[0]; - taskList.sort((a, b) => - a.clientAuditDetails?.createdTime - .compareTo(b.clientAuditDetails!.createdTime) ?? - 0); + taskList = sortTasks(taskList); + sideEffectsList = tasksRelated[1]; referralsList = tasksRelated[2]; diff --git a/packages/registration_delivery/lib/utils/utils.dart b/packages/registration_delivery/lib/utils/utils.dart index c9fc6d2a9..bad6c15da 100644 --- a/packages/registration_delivery/lib/utils/utils.dart +++ b/packages/registration_delivery/lib/utils/utils.dart @@ -476,3 +476,12 @@ Status getTaskStatus(Iterable tasks) { return Status.registered.toValue(); } + +List sortTasks(List tasks) { + tasks.sort((a, b) { + return a.clientAuditDetails?.lastModifiedTime + ?.compareTo(b.clientAuditDetails!.lastModifiedTime!) ?? + 0; + }); + return tasks; +}