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

[GSoC] - Refactoring, common alert popup & test #889

Merged
merged 2 commits into from
Jun 15, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: chmod +x ./.github/workflows/countline.py
- run: ./.github/workflows/countline.py --exclude lib/custom_painters/talawa_logo.dart lib/utils/queries.dart
- run: ./.github/workflows/countline.py --exclude lib/custom_painters/talawa_logo.dart lib/utils/queries.dart test/widget_tests/set_url_page_test.dart

Trailing-Comma-Pattern:
name: Trailing comma added at the end of every required code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: chmod +x ./.github/workflows/countline.py
- run: ./.github/workflows/countline.py --exclude lib/custom_painters/talawa_logo.dart lib/utils/queries.dart
- run: ./.github/workflows/countline.py --exclude lib/custom_painters/talawa_logo.dart lib/utils/queries.dart test/widget_tests/set_url_page_test.dart

Trailing-Comma-Pattern:
name: Trailing comma added at the end of every required code
Expand Down
6 changes: 5 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linter:

avoid_redundant_argument_values: false

# Unessary use of this in contructors should not be done
# Unnecessary use of this in constructors should not be done
unnecessary_this: false

# source files name using lowercase_with_underscores
Expand All @@ -27,6 +27,10 @@ linter:
always_declare_return_types: false

type_annotate_public_apis: false
#always_use_package_imports to make a quick navigation to particular files
always_use_package_imports: true

directives_ordering: true

# In case of production should be set to true
avoid_print: false
Expand Down
6 changes: 4 additions & 2 deletions lib/constants/custom_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class TalawaTheme {
colorScheme: const ColorScheme.light(
primaryVariant: _lightPrimaryVariantColor,
primary: _lightColorSchemePrimary,
secondary: Color(0xffF5F5F5)),
secondary: Color(0xffF5F5F5),
secondaryVariant: _darkScaffoldColor),
accentColor: _lightAccentColor,
iconTheme: const IconThemeData(
color: _lightIconColor,
Expand All @@ -46,7 +47,8 @@ class TalawaTheme {
colorScheme: const ColorScheme.dark(
primaryVariant: _darkPrimaryVariantColor,
primary: _darkColorSchemePrimary,
secondary: Colors.black),
secondary: Colors.black,
secondaryVariant: _lightScaffoldColor),
iconTheme: const IconThemeData(
color: _darkIconColor,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/routing_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Routes {
static const String mainScreen = "/mainScreen";
static const String progressDialog = "/progress";
static const String individualPost = "/individualPost";
static const String pinnedPostpage = "/pinnedPostPage";
static const String pinnedPostPage = "/pinnedPostPage";
static const String exploreEventsScreen = "/exploreEvents";
static const String eventInfoPage = "/eventInfo";
static const String createEventPage = "/createEventPage";
Expand Down
19 changes: 19 additions & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Generated file. Do not edit.
//

// ignore_for_file: lines_longer_than_80_chars

import 'package:connectivity_plus_web/connectivity_plus_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:uni_links_web/uni_links_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
ConnectivityPlusPlugin.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar);
UniLinksPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
15 changes: 10 additions & 5 deletions lib/locator.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import 'package:get_it/get_it.dart';
import 'package:talawa/main.dart';
import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/view_model/demo_view_model.dart';
import 'package:talawa/view_model/edit_profile_view_model.dart';
import 'package:talawa/view_model/explore_events_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/event_view_models/explore_events_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/feed_view_models/organization_feed_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/edit_profile_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart';
import 'package:talawa/view_model/main_screen_view_model.dart';
import 'package:talawa/view_model/organization_feed_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/login_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/select_organization_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/set_url_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/signup_details_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/waiting_view_model.dart';
import 'package:talawa/view_model/profile_page_view_model.dart';
import 'package:talawa/view_model/widgets_view_models/custom_drawer_view_model.dart';
import 'package:talawa/view_model/widgets_view_models/progress_dialog_view_model.dart';

GetIt locator = GetIt.instance;
final userConfig = locator<UserConfig>();
final navigationService = locator<NavigationService>();
final databaseFunctions = locator<DataBaseMutationFunctions>();
final graphqlConfig = locator<GraphqlConfig>();
final sizeConfig = locator<SizeConfig>();

void setupLocator() {
//services
Expand Down
17 changes: 10 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path;
import 'package:talawa/constants/custom_theme.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/router.dart' as router;
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/view_model/demo_view_model.dart';
import 'package:talawa/view_model/base_view_model.dart';
import 'package:talawa/views/base_view.dart';

import 'constants/custom_theme.dart';
import 'models/organization/org_info.dart';
import 'models/user/user_info.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final Directory dir = await path.getApplicationDocumentsDirectory();
Expand All @@ -37,7 +35,7 @@ class MyApp extends StatelessWidget {
theme: TalawaTheme.lightTheme,
darkTheme: TalawaTheme.darkTheme,
debugShowCheckedModeBanner: false,
navigatorKey: locator<NavigationService>().navigatorKey,
navigatorKey: navigationService.navigatorKey,
onGenerateRoute: router.generateRoute,
initialRoute: '/',
);
Expand All @@ -61,3 +59,8 @@ class DemoPageView extends StatelessWidget {
);
}
}

class DemoViewModel extends BaseModel {
final String _title = "Title from the viewMode GSoC branch";
String get title => _title;
}
13 changes: 6 additions & 7 deletions lib/router.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:talawa/constants/routing_constants.dart';
import 'package:talawa/main.dart';
import 'package:talawa/models/events/event_model.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/post/post_model.dart';
import 'package:talawa/splash_screen.dart';
import 'package:talawa/views/after_auth_screens/events/create_event_page.dart';
import 'package:talawa/views/after_auth_screens/events/event_info_page.dart';
import 'package:talawa/views/after_auth_screens/events/explore_events.dart';
import 'package:talawa/views/after_auth_screens/feed_page/individual_post.dart';
import 'package:talawa/views/after_auth_screens/feed_page/organization_feed.dart';
import 'package:talawa/views/after_auth_screens/feed_page/pinned_post_page.dart';
import 'package:talawa/views/after_auth_screens/feed/individual_post.dart';
import 'package:talawa/views/after_auth_screens/feed/organization_feed.dart';
import 'package:talawa/views/after_auth_screens/feed/pinned_post_page.dart';
import 'package:talawa/views/after_auth_screens/profile/edit_profile_page.dart';
import 'package:talawa/views/after_auth_screens/profile/profile_page.dart';
import 'package:talawa/views/main_screen.dart';
Expand All @@ -22,9 +24,6 @@ import 'package:talawa/views/pre_auth_screens/set_url.dart';
import 'package:talawa/views/pre_auth_screens/signup_details.dart';
import 'package:talawa/views/pre_auth_screens/waiting_to_join_private_org.dart';

import 'constants/routing_constants.dart';
import 'models/events/event_model.dart';

Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case Routes.splashScreen:
Expand Down Expand Up @@ -83,7 +82,7 @@ Route<dynamic> generateRoute(RouteSettings settings) {
key: const Key('IndividualPost'),
post: post,
));
case Routes.pinnedPostpage:
case Routes.pinnedPostPage:
final List<Post> pinnedPosts = settings.arguments! as List<Post>;
return MaterialPageRoute(
builder: (context) => PinnedPostPage(pinnedPosts: pinnedPosts));
Expand Down
53 changes: 22 additions & 31 deletions lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/utils/queries.dart';
import 'package:talawa/widgets/progress_dialog.dart';

class DataBaseMutationFunctions {
late GraphQLClient clientNonAuth;
late GraphQLClient clientAuth;
late NavigationService navigatorService;
late UserConfig userConfig;
late Queries _query;

init() {
clientNonAuth = locator<GraphqlConfig>().clientToQuery();
clientAuth = locator<GraphqlConfig>().authClient();
navigatorService = locator<NavigationService>();
userConfig = locator<UserConfig>();
clientNonAuth = graphqlConfig.clientToQuery();
clientAuth = graphqlConfig.authClient();
_query = Queries();
}

Expand All @@ -40,13 +33,13 @@ class DataBaseMutationFunctions {
bool? encounteredExceptionOrError(OperationException exception,
{bool showSnackBar = true}) {
if (exception.linkException != null) {
print(exception.linkException);
debugPrint(exception.linkException.toString());
if (showSnackBar) {
navigatorService.showSnackBar("Server not running/wrong url");
navigationService.showSnackBar("Server not running/wrong url");
}
return false;
} else {
print(exception.graphqlErrors);
debugPrint(exception.graphqlErrors.toString());
for (int i = 0; i < exception.graphqlErrors.length; i++) {
if (exception.graphqlErrors[i].message ==
refreshAccessTokenExpiredException.message) {
Expand All @@ -56,32 +49,32 @@ class DataBaseMutationFunctions {
return true;
} else if (exception.graphqlErrors[i].message == userNotFound.message) {
if (showSnackBar) {
navigatorService
navigationService
.showSnackBar("No account registered with this email");
}
return false;
} else if (exception.graphqlErrors[i].message ==
wrongCredentials.message) {
if (showSnackBar) {
navigatorService.showSnackBar("Enter a valid password");
navigationService.showSnackBar("Enter a valid password");
}
return false;
} else if (exception.graphqlErrors[i].message ==
organizationNotFound.message) {
if (showSnackBar) {
navigatorService.showSnackBar("Organization Not Found");
navigationService.showSnackBar("Organization Not Found");
}
return false;
} else if (exception.graphqlErrors[i].message ==
emailAccountPresent.message) {
if (showSnackBar) {
navigatorService
navigationService
.showSnackBar("Account with this email already registered");
}
return false;
}
}
navigatorService.showSnackBar("Something went wrong");
navigationService.showSnackBar("Something went wrong");
return false;
}
}
Expand All @@ -98,10 +91,9 @@ class DataBaseMutationFunctions {
if (exception!) {
refreshAccessToken(refreshToken);
} else {
navigatorService.pop();
navigationService.pop();
}
} else if (result.data != null && result.isConcrete) {
print(result.data);
userConfig.updateAccessToken(
refreshToken: result.data!['refreshToken']['refreshToken'].toString(),
accessToken: result.data!['refreshToken']['accessToken'].toString());
Expand All @@ -111,7 +103,7 @@ class DataBaseMutationFunctions {
}

Future<bool> login(String email, String password) async {
navigatorService
navigationService
.pushDialog(const ProgressDialog(key: Key('LoginProgress')));

final QueryResult result = await clientNonAuth.mutate(
Expand All @@ -121,19 +113,19 @@ class DataBaseMutationFunctions {
if (exception!) {
login(email, password);
} else {
navigatorService.pop();
navigationService.pop();
}
} else if (result.data != null && result.isConcrete) {
navigatorService.pop();
navigationService.pop();
final User loggedInUser =
User.fromJson(result.data!['login'] as Map<String, dynamic>);
userConfig.updateUser(loggedInUser);
if (userConfig.currentUser.joinedOrganizations!.isEmpty) {
navigatorService.removeAllAndPush('/waiting', '/');
navigationService.removeAllAndPush('/waiting', '/');
} else {
userConfig.saveCurrentOrgInHive(
userConfig.currentUser.joinedOrganizations![0]);
navigatorService.removeAllAndPush('/mainScreen', '/');
navigationService.removeAllAndPush('/mainScreen', '/');
}
return true;
}
Expand All @@ -142,7 +134,7 @@ class DataBaseMutationFunctions {

Future<bool> signup(
String firstName, String lastName, String email, String password) async {
navigatorService
navigationService
.pushDialog(const ProgressDialog(key: Key('SignUpProgress')));

final QueryResult result = await clientNonAuth.mutate(MutationOptions(
Expand All @@ -153,19 +145,19 @@ class DataBaseMutationFunctions {
if (exception!) {
login(email, password);
} else {
navigatorService.pop();
navigationService.pop();
}
} else if (result.data != null && result.isConcrete) {
final User signedInUser =
User.fromJson(result.data!['signUp'] as Map<String, dynamic>);
final bool userSaved = await userConfig.updateUser(signedInUser);
return userSaved;
final bool tokenRefreshed = await graphqlConfig.getToken() as bool;
return userSaved && tokenRefreshed;
}
return false;
}

Future<bool> joinPublicOrg(String id) async {
print(id);
final QueryResult result = await clientAuth
.mutate(MutationOptions(document: gql(_query.joinOrgById(id))));

Expand All @@ -182,7 +174,6 @@ class DataBaseMutationFunctions {
['joinedOrganizations'] as List<dynamic>?)
?.map((e) => OrgInfo.fromJson(e as Map<String, dynamic>))
.toList();
print(joinedOrg);
userConfig.updateUserJoinedOrg(joinedOrg!);
//navigatorService.pop();
return true;
Expand All @@ -199,14 +190,14 @@ class DataBaseMutationFunctions {
refreshAccessToken(userConfig.currentUser.refreshToken!);
sendMembershipRequest(id);
} else {
navigatorService.pop();
navigationService.pop();
}
} else if (result.data != null && result.isConcrete) {
final OrgInfo membershipRequest = OrgInfo.fromJson(
result.data!['sendMembershipRequest']['organization']
as Map<String, dynamic>);
userConfig.updateUserMemberRequestOrg([membershipRequest]);
navigatorService.pop();
navigationService.pop();
return true;
}
return false;
Expand Down
Loading