Skip to content

Commit 8f59567

Browse files
committed
feat: Remove Scores table and update UI
1 parent bf9f14a commit 8f59567

20 files changed

+781
-2273
lines changed

lib/presentation/bloc/nfc_pass_bloc/nfc_pass_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class NfcPassBloc extends Bloc<NfcPassEvent, NfcPassState> {
137137
(failure) => studentId = null,
138138
(userData) {
139139
// Prevent multiple fetches of user profile data
140-
userBloc.add(UserEvent.setAuntificatedData(user: userData));
140+
userBloc.add(SetAuthenticatedData(user: userData));
141141

142142
var student = userData.students
143143
.firstWhereOrNull((element) => element.status == 'активный');

lib/presentation/bloc/user_bloc/user_bloc.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:bloc/bloc.dart';
2+
import 'package:equatable/equatable.dart';
23
import 'package:firebase_analytics/firebase_analytics.dart';
3-
import 'package:freezed_annotation/freezed_annotation.dart';
44
import 'package:get/get.dart';
55
import 'package:rtu_mirea_app/domain/entities/student.dart';
66
import 'package:rtu_mirea_app/domain/entities/user.dart';
@@ -12,7 +12,6 @@ import 'package:sentry_flutter/sentry_flutter.dart';
1212

1313
part 'user_event.dart';
1414
part 'user_state.dart';
15-
part 'user_bloc.freezed.dart';
1615

1716
class UserBloc extends Bloc<UserEvent, UserState> {
1817
final LogIn logIn;
@@ -25,19 +24,19 @@ class UserBloc extends Bloc<UserEvent, UserState> {
2524
required this.logOut,
2625
required this.getUserData,
2726
required this.getAuthToken,
28-
}) : super(const _Unauthorized()) {
29-
on<_LogIn>(_onLogInEvent);
30-
on<_LogOut>(_onLogOutEvent);
31-
on<_Started>(_onGetUserDataEvent);
32-
on<_GetUserData>(_onGetUserDataEvent);
33-
on<_SetAuntificatedData>(_onSetAuntificatedDataEvent);
27+
}) : super(const UserState()) {
28+
on<LogInEvent>(_onLogInEvent);
29+
on<LogOutEvent>(_onLogOutEvent);
30+
on<Started>(_onGetUserDataEvent);
31+
on<GetUserDataEvent>(_onGetUserDataEvent);
32+
on<SetAuthenticatedData>(_onSetAuntificatedDataEvent);
3433
}
3534

3635
void _onSetAuntificatedDataEvent(
37-
_SetAuntificatedData event,
36+
SetAuthenticatedData event,
3837
Emitter<UserState> emit,
3938
) async {
40-
emit(_LogInSuccess(event.user));
39+
emit(state.copyWith(status: UserStatus.authorized, user: event.user));
4140
}
4241

4342
void _setSentryUserIdentity(String id, String email, String group) {
@@ -49,7 +48,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
4948
UserEvent event,
5049
Emitter<UserState> emit,
5150
) async {
52-
if (state is _LogInSuccess) return;
51+
if (state.status == UserStatus.authorized) return;
5352

5453
// We use oauth2 to get token. So we don't need to pass login and password
5554
// to the server. We just need to pass them to the oauth2 server.
@@ -59,26 +58,25 @@ class UserBloc extends Bloc<UserEvent, UserState> {
5958
final logInRes = await logIn();
6059

6160
logInRes.fold(
62-
(failure) => emit(_LogInError(
63-
failure.cause ?? "Ошибка при авторизации. Повторите попытку")),
61+
(failure) => emit(state.copyWith(status: UserStatus.authorizeError)),
6462
(res) {
6563
loggedIn = true;
6664
},
6765
);
6866

6967
if (loggedIn) {
70-
emit(const _Loading());
68+
emit(state.copyWith(status: UserStatus.loading));
7169
final user = await getUserData();
7270

7371
user.fold(
74-
(failure) => emit(const _Unauthorized()),
72+
(failure) => emit(state.copyWith(status: UserStatus.unauthorized)),
7573
(user) {
7674
FirebaseAnalytics.instance.logLogin();
7775
var student = getActiveStudent(user);
7876

7977
_setSentryUserIdentity(
8078
user.id.toString(), user.login, student.academicGroup);
81-
emit(_LogInSuccess(user));
79+
emit(state.copyWith(status: UserStatus.authorized, user: user));
8280
},
8381
);
8482
}
@@ -89,7 +87,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
8987
Emitter<UserState> emit,
9088
) async {
9189
final res = await logOut();
92-
res.fold((failure) => null, (r) => emit(const _Unauthorized()));
90+
res.fold((failure) => null, (r) => emit(state.copyWith()));
9391
}
9492

9593
static Student getActiveStudent(User user) {
@@ -103,7 +101,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
103101
UserEvent event,
104102
Emitter<UserState> emit,
105103
) async {
106-
if (state is _LogInSuccess) return;
104+
if (state.status == UserStatus.authorized) return;
107105

108106
final token = await getAuthToken();
109107

@@ -113,14 +111,16 @@ class UserBloc extends Bloc<UserEvent, UserState> {
113111

114112
// If token in the storage, user is authorized at least once and we can
115113
// try to get user data
116-
emit(const _Loading());
114+
emit(state.copyWith(status: UserStatus.loading));
117115
final user = await getUserData();
118116

119-
user.fold((failure) => emit(const _Unauthorized()), (r) {
117+
user.fold(
118+
(failure) => emit(state.copyWith(status: UserStatus.unauthorized)),
119+
(r) {
120120
var student = getActiveStudent(r);
121121

122122
_setSentryUserIdentity(r.id.toString(), r.login, student.academicGroup);
123-
emit(_LogInSuccess(r));
123+
emit(state.copyWith(status: UserStatus.authorized, user: r));
124124
});
125125
}
126126
}

0 commit comments

Comments
 (0)