diff --git a/frontend/app_student/lib/api/users/repositories/user_repository.dart b/frontend/app_student/lib/api/users/repositories/user_repository.dart index 88e7c02..da4596a 100644 --- a/frontend/app_student/lib/api/users/repositories/user_repository.dart +++ b/frontend/app_student/lib/api/users/repositories/user_repository.dart @@ -34,4 +34,17 @@ class UserRepository { await prefs.setString('birthDate', birthDate); await prefs.setString('className', className); } + + Future deleteUser() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.remove('ine'); + await prefs.remove('name'); + await prefs.remove('birthDate'); + await prefs.remove('className'); + } + + Future saveUserClass(String className) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString('className', className); + } } diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart index 2463fd7..3dcb97d 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart @@ -29,4 +29,9 @@ class ClassGroupCubit extends Cubit { Future getConnectedUser() async { return userRepository.getUser(); } + + Future saveClass(ClassGroupModel classGroup) async { + await userRepository.saveUserClass(classGroup.toString()); + emit(ClassGroupSelected()); + } } diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_state.dart b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart index acdc666..b1ac586 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_state.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart @@ -18,3 +18,5 @@ class ClassGroupError extends ClassGroupState { ClassGroupError([this.message = 'An error occurred']); } + +class ClassGroupSelected extends ClassGroupState {} diff --git a/frontend/app_student/lib/class_groups/views/class_group_page.dart b/frontend/app_student/lib/class_groups/views/class_group_page.dart index ca93e8d..174b001 100644 --- a/frontend/app_student/lib/class_groups/views/class_group_page.dart +++ b/frontend/app_student/lib/class_groups/views/class_group_page.dart @@ -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'; @@ -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: [ diff --git a/frontend/app_student/lib/class_groups/views/widgets/card_list.dart b/frontend/app_student/lib/class_groups/views/widgets/card_list.dart index c2f6d98..c20ecb0 100644 --- a/frontend/app_student/lib/class_groups/views/widgets/card_list.dart +++ b/frontend/app_student/lib/class_groups/views/widgets/card_list.dart @@ -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 classesList; @@ -17,6 +20,9 @@ class CardList extends StatelessWidget { title: Text( classesList[index].name, ), + onTap: () { + context.read().saveClass(classesList[index]); + }, ), ); }, diff --git a/frontend/app_student/lib/login/views/login_page.dart b/frontend/app_student/lib/login/views/login_page.dart index e18693d..9b7a0e9 100644 --- a/frontend/app_student/lib/login/views/login_page.dart +++ b/frontend/app_student/lib/login/views/login_page.dart @@ -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'; @@ -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) {