Skip to content

Commit

Permalink
Formate code
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Aug 2, 2023
1 parent e0e0b1d commit 167bbc1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
11 changes: 11 additions & 0 deletions lib/data/core/extensions/list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:projectunity/data/model/leave_application.dart';

extension Iterables<E> on Iterable<E> {
Map<K, List<E>> groupBy<K>(K Function(E) keyFunction) => fold(
<K, List<E>>{},
Expand All @@ -14,3 +16,12 @@ extension IterableListMergeExtension<T> on Iterable<List<T>> {
return mergedList;
}
}

extension ConvertListToMapExtension on List<LeaveApplication> {
Map<DateTime, List<LeaveApplication>> groupByAppliedOnMonth() {
sort((a, b) => b.leave.appliedOn.compareTo(a.leave.appliedOn));
return groupBy((leaveApplication) => DateTime(
leaveApplication.leave.appliedOn.year,
leaveApplication.leave.appliedOn.month));
}
}
File renamed without changes.
32 changes: 11 additions & 21 deletions lib/ui/admin/leaves/leave_screen/bloc /admin_leaves_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../../../../../data/Repo/leave_repo.dart';
import '../../../../../data/core/exception/error_const.dart';
import '../../../../../data/model/employee/employee.dart';
import '../../../../../data/model/leave/leave.dart';
import '../../../../../data/model/leave_application.dart';
import 'admin_leave_event.dart';
import 'admin_leaves_state.dart';

Expand Down Expand Up @@ -55,9 +54,9 @@ class AdminLeavesBloc extends Bloc<AdminLeavesEvents, AdminLeavesState> {
_lastDoc = paginatedData.lastDoc;
emit(state.copyWith(
leavesFetchStatus: Status.success,
leaveApplicationMap: convertListToMap(
getLeaveApplicationFromLeaveEmployee(
leaves: paginatedData.leaves, members: _members))));
leaveApplicationMap: getLeaveApplicationFromLeaveEmployee(
leaves: paginatedData.leaves, members: _members)
.groupByAppliedOnMonth()));
} on Exception {
emit(state.copyWith(
leavesFetchStatus: Status.error,
Expand All @@ -76,14 +75,14 @@ class AdminLeavesBloc extends Bloc<AdminLeavesEvents, AdminLeavesState> {
if (paginatedData.lastDoc == _lastDoc) {
_isLoadedMax = true;
}
_lastDoc = paginatedData.lastDoc;
final leaveApplications = state.leaveApplicationMap.values.merge();
leaveApplications.addAll(getLeaveApplicationFromLeaveEmployee(
leaves: paginatedData.leaves, members: _members));
emit(state.copyWith(
leavesFetchStatus: Status.success,
showPaginationLoading: false,
leaveApplicationMap: convertListToMap(leaveApplications)));
_lastDoc = paginatedData.lastDoc;
final leaveApplications = state.leaveApplicationMap.values.merge();
leaveApplications.addAll(getLeaveApplicationFromLeaveEmployee(
leaves: paginatedData.leaves, members: _members));
emit(state.copyWith(
leavesFetchStatus: Status.success,
showPaginationLoading: false,
leaveApplicationMap: leaveApplications.groupByAppliedOnMonth()));
} on Exception {
emit(state.copyWith(
leavesFetchStatus: Status.error,
Expand All @@ -93,15 +92,6 @@ class AdminLeavesBloc extends Bloc<AdminLeavesEvents, AdminLeavesState> {
}
}

Map<DateTime, List<LeaveApplication>> convertListToMap(
List<LeaveApplication> leaveApplications) {
leaveApplications
.sort((a, b) => b.leave.appliedOn.compareTo(a.leave.appliedOn));
return leaveApplications.groupBy((leaveApplication) => DateTime(
leaveApplication.leave.appliedOn.year,
leaveApplication.leave.appliedOn.month));
}

void _searchEmployee(
SearchEmployeeEvent event, Emitter<AdminLeavesState> emit) {
emit(state.copyWith(
Expand Down

0 comments on commit 167bbc1

Please sign in to comment.