Skip to content

Commit

Permalink
WIP- Implement real time updates for User- Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneha-s committed Jul 24, 2023
1 parent 066f52e commit 4c133d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
13 changes: 4 additions & 9 deletions lib/data/bloc/user_state/space_user_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ class SpaceUserBloc extends Bloc<SpaceUserEvent, SpaceUserState> {

Future<void> _checkUserStatus(
CheckSpaceEvent status, Emitter<SpaceUserState> emit) async {
if (_spaceManager.currentSpaceId == null) {
if (_userStateNotifier.employee != null ||
_userStateNotifier.currentSpace != null) {
add(DeactivateUserEvent());
}
} else {
if (_spaceManager.currentSpaceId != null) {
final Space? space =
await _spaceService.getSpace(_spaceManager.currentSpaceId!);
if (space == null) {
return;
}
_userStateNotifier.updateSpace(space);
await _userStateNotifier.updateSpace(space);
if (_streamSubscription != null) {
_streamSubscription!.cancel();
}
Expand All @@ -65,7 +60,7 @@ class SpaceUserBloc extends Bloc<SpaceUserEvent, SpaceUserState> {
.listen((event) {
_userController.add(event);
add(CheckUserEvent(employee: event));
}, onError: (error, stackTrace) {
}, onError: (error, stackTrace) async {
emit(SpaceUserErrorState(error: firestoreFetchDataError));
FirebaseCrashlytics.instance.recordError(error, stackTrace,
reason: 'ERROR WHILE LISTENING THE CURRENT USER STRAEM');
Expand All @@ -87,7 +82,7 @@ class SpaceUserBloc extends Bloc<SpaceUserEvent, SpaceUserState> {
if (event.employee!.status == EmployeeStatus.inactive) {
emit(SpaceUserRevokeAccessState());
} else {
_userStateNotifier.updateCurrentUser(event.employee!);
await _userStateNotifier.updateCurrentUser(event.employee!);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/data/provider/user_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class UserStateNotifier with ChangeNotifier {
Future<void> updateCurrentUser(Employee user)async {
if (_userPreference.getEmployee() == null) {
_userState = UserState.spaceJoined;
return;
await _userPreference.setEmployee(user);
notifyListeners();
}
// if(_userPreference.getEmployee()?.role!=user.role){
// _userState= UserState.update;
// }

await _userPreference.setEmployee(user);
_userState = UserState.update;
notifyListeners();
if (_userPreference.getEmployee()?.role != user.role) {
_userState = UserState.update;
await _userPreference.setEmployee(user);
notifyListeners();
}
_userState = UserState.spaceJoined;
}

Future<void> updateSpace(Space space) async {
Expand Down
10 changes: 4 additions & 6 deletions lib/ui/navigation/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,16 @@ class AppRouter {
!state.subloc.contains(Routes.joinSpace)) {
return Routes.joinSpace;
}
if ((userManager.state == UserState.spaceJoined &&
state.subloc.contains(Routes.joinSpace))) {
if (_userManager.state == UserState.spaceJoined &&
state.subloc.contains(Routes.joinSpace)) {
return userManager.isAdmin || userManager.isHR
? Routes.adminHome
: Routes.userHome;
}
if (_userManager.state == UserState.update) {
print(state.location);
context.replaceNamed(userManager.isAdmin || userManager.isHR
return userManager.isAdmin || userManager.isHR
? Routes.adminHome
: Routes.userHome);
return state.location;
: Routes.userHome;
}
return null;
});
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/shared/who_is_out_card/who_is_out_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class WhoIsOutCard extends StatelessWidget {
BlocBuilder<WhoIsOutCardBloc, WhoIsOutCardState>(
buildWhen: (previous, current) =>
previous.status != current.status ||
previous.selectedDayAbsences !=
current.selectedDayAbsences ||
previous.selectedDate != current.selectedDate,
builder: (context, state) =>
AbsenceEmployeesListWhoIsOutCardView(
Expand Down

0 comments on commit 4c133d7

Please sign in to comment.