Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/menu #76

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions frontend/app_student/lib/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:app_student/login/views/login_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';

import '../../users/cubit/user_cubit.dart';

Expand All @@ -12,23 +11,12 @@ class LoginPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BlocConsumer<LoginCubit, LoginState>(
listener: (context, state) {},
return BlocBuilder<LoginCubit, LoginState>(
builder: (context, state) {
return BlocBuilder<UserCubit, UserState>(
builder: (context, userState) {
if (state is RedirectToClassSelection) {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.go('/classList');
});
return Container();
} else if (state is LoginInitial) {
if (state is LoginInitial) {
return LoginView(AppLocalizations.of(context)!.loginWelcomeTitle);
} else if (state is LoginAuthenticated) {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.go('/schedule');
});
return Container();
} else if (state is LoginFieldError) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(
Expand All @@ -42,7 +30,8 @@ class LoginPage extends StatelessWidget {
return LoginView(
AppLocalizations.of(context)!.loginWelcomeTitleError);
} else {
return Container();
return const Scaffold(
body: Center(child: CircularProgressIndicator()));
}
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';

import '../../../../users/cubit/user_cubit.dart';

Expand All @@ -21,9 +22,14 @@ class SubmitButton extends StatelessWidget {
text: AppLocalizations.of(context)!.loginButton,
onPressed: () async {
final String name = nameController.text.trim();
await context.read<LoginCubit>().saveLoginDetails(name);
if (context.mounted) {
await context.read<UserCubit>().fetchUser();
final loginCubit = context.read<LoginCubit>();
final userCubit = context.read<UserCubit>();

await loginCubit.saveLoginDetails(name);
await userCubit.fetchUser();

if (userCubit.state is UserWithoutClass && context.mounted) {
GoRouter.of(context).push('/classList');
}
},
backgroundColor: CustomTheme.secondaryColor,
Expand Down
8 changes: 4 additions & 4 deletions frontend/app_student/lib/menu/menu_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MenuBarViewState extends State<MenuBarView> {
void _setSelectedIndex() {
final route = GoRouter.of(context).routeInformationProvider.value.uri.path;

if (route == AppRoutes.loginPage) {
if (route == AppRoutes.schoolSpace) {
_selectedIndex = 0;
} else if (route == AppRoutes.schedulePage) {
_selectedIndex = 1;
Expand All @@ -40,13 +40,13 @@ class MenuBarViewState extends State<MenuBarView> {

switch (index) {
case 0:
GoRouter.of(context).go(AppRoutes.schoolSpace);
GoRouter.of(context).pushReplacement(AppRoutes.schoolSpace);
break;
case 1:
GoRouter.of(context).go(AppRoutes.schedulePage);
GoRouter.of(context).pushReplacement(AppRoutes.schedulePage);
break;
case 2:
GoRouter.of(context).go(AppRoutes.profilPage);
GoRouter.of(context).pushReplacement(AppRoutes.profilPage);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app_student/lib/profil/views/profil_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ProfilPage extends StatelessWidget {
body: BlocBuilder<UserCubit, UserState>(
builder: (context, state) {
if (state is UserLoading) {
return Container();
return const CircularProgressIndicator();
} else if (state is UserWihtoutLink) {
final user = state.user;
return Column(
Expand Down
85 changes: 66 additions & 19 deletions frontend/app_student/lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class AppRoutes {

static final routes = [
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final userCubit = context.read<UserCubit>();
if (userCubit.state is UserWithoutClass) {
return classListPage;
} else if ((userCubit.state is UserWihtoutLink) ||
(userCubit.state is UserLoggedIn)) {
return schedulePage;
}

return loginPage;
},
path: classListPage,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
Expand All @@ -47,24 +58,18 @@ class AppRoutes {
], child: const ClassGroupPage()),
),
),
// redirect: (context, state) {
// final loginCubit = context.read<LoginCubit>();
// if (loginCubit.state is RedirectToClassSelection) {
// return classListPage;
// }
// return null;
// },
),
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final loginCubit = context.read<LoginCubit>();
final userCubit = context.read<UserCubit>();
if (loginCubit.state is LoginAuthenticated) {
if (userCubit.state is UserWithoutClass) {
return classListPage;
}

if (userCubit.state is UserWithoutClass) {
return classListPage;
} else if ((userCubit.state is UserWihtoutLink) ||
(userCubit.state is UserLoggedIn)) {
return schedulePage;
}

return loginPage;
},
path: loginPage,
Expand All @@ -82,6 +87,18 @@ class AppRoutes {
),
),
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final userCubit = context.read<UserCubit>();

if ((userCubit.state is UserWihtoutLink) ||
(userCubit.state is UserLoggedIn)) {
return schedulePage;
} else if (userCubit.state is UserWithoutClass) {
return classListPage;
}

return loginPage;
},
path: schedulePage,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
Expand All @@ -108,29 +125,59 @@ class AppRoutes {
),
),
),
// redirect: (context, state) {
// final loginCubit = context.read<LoginCubit>();
// if (loginCubit.state is LoginAuthenticated) {
// return schedulePage;
// }
// return null;
// },
),
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final userCubit = context.read<UserCubit>();

if ((userCubit.state is UserWihtoutLink) ||
(userCubit.state is UserLoggedIn)) {
return profilPage;
} else if (userCubit.state is UserWithoutClass) {
return classListPage;
}

return loginPage;
},
path: profilPage,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
child: const ProfilPage(),
),
),
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final userCubit = context.read<UserCubit>();

if ((userCubit.state is UserWihtoutLink) ||
(userCubit.state is UserLoggedIn)) {
return schoolSpace;
} else if (userCubit.state is UserWithoutClass) {
return classListPage;
}

return loginPage;
},
path: schoolSpace,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
child: const SchoolSpacePage(),
),
),
GoRoute(
redirect: (BuildContext context, GoRouterState state) {
final userCubit = context.read<UserCubit>();

if (userCubit.state is UserWihtoutLink) {
return linkAccountFormPage;
} else if (userCubit.state is UserLoggedIn) {
return schoolSpace;
} else if (userCubit.state is UserWithoutClass) {
return classListPage;
}

return loginPage;
},
path: linkAccountFormPage, // Use the new constant here
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class SchoolSpacePageState extends State<SchoolSpacePage> {
),
],
);
} else if (state is UserError) {
return Center(
child: Text(state.message),
);
} else {
return const SizedBox.shrink();
}
Expand Down
Loading