Skip to content

Commit

Permalink
✨: added routes + cache for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPLukaas committed Mar 13, 2024
1 parent 92bd64f commit a9614fa
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ class UserRepository {
await prefs.setString('birthDate', birthDate);
await prefs.setString('className', className);
}

Future<void> deleteUser() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove('ine');
await prefs.remove('name');
await prefs.remove('birthDate');
await prefs.remove('className');
}

Future<void> saveUserClass(String className) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('className', className);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ class ClassGroupCubit extends Cubit<ClassGroupState> {
Future<UserModel> getConnectedUser() async {
return userRepository.getUser();
}

Future<void> saveClass(ClassGroupModel classGroup) async {
await userRepository.saveUserClass(classGroup.toString());
emit(ClassGroupSelected());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ class ClassGroupError extends ClassGroupState {

ClassGroupError([this.message = 'An error occurred']);
}

class ClassGroupSelected extends ClassGroupState {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_student/class_groups/views/widgets/header/header_text.dart';
import 'package:app_student/class_groups/views/widgets/header/header_title.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

import '../../api/users/models/user_model.dart';
import '../../api/users/repositories/user_repository.dart';
Expand Down Expand Up @@ -37,6 +38,11 @@ class ClassGroupPage extends StatelessWidget {
builder: (context, state) {
if (state is ClassGroupLoading) {
return const Center(child: CircularProgressIndicator());
} else if (state is ClassGroupSelected) {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.go('/schedule');
});
return const SizedBox.shrink();
} else if (state is ClassGroupLoaded) {
return Column(
children: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:app_student/api/class_groups/models/class_group_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../cubit/class_group_cubit.dart';

class CardList extends StatelessWidget {
final List<ClassGroupModel> classesList;
Expand All @@ -17,6 +20,9 @@ class CardList extends StatelessWidget {
title: Text(
classesList[index].name,
),
onTap: () {
context.read<ClassGroupCubit>().saveClass(classesList[index]);
},
),
);
},
Expand Down
5 changes: 1 addition & 4 deletions frontend/app_student/lib/login/views/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:app_student/login/cubit/login_cubit.dart';
import 'package:app_student/login/widgets/form/form_login.dart';
import 'package:app_student/login/widgets/header/header_text.dart';
import 'package:app_student/week_schedule/views/week_schedule.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -32,9 +31,7 @@ class LoginPage extends StatelessWidget {
);
} else if (state is LoginAuthenticated) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const WeekSchedulePage()),
);
context.go('/schedule');
});
return Container();
} else if (state is LoginFieldError) {
Expand Down

0 comments on commit a9614fa

Please sign in to comment.