Skip to content

Commit c2f4532

Browse files
authored
Merge pull request #238 from RunTerror/new_beacon_branch
Auth home and cubit module migration
2 parents 72c1c09 + f547313 commit c2f4532

File tree

74 files changed

+5004
-1479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5004
-1479
lines changed

lib/Bloc/config/graphql_config.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ class GraphQLConfig {
2020
));
2121

2222
Future getToken() async {
23-
final _token = userConfig!.currentUser!.authToken;
24-
token = _token;
23+
await localApi.init();
24+
final user = await localApi.fetchUser();
25+
if (user != null) {
26+
token = user.authToken;
27+
}
2528
return true;
2629
}
2730

2831
GraphQLClient clientToQuery() {
2932
return GraphQLClient(
30-
cache: GraphQLCache(),
31-
// cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
33+
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
3234
link: httpLink,
3335
);
3436
}
@@ -45,7 +47,7 @@ class GraphQLConfig {
4547

4648
GraphQLClient graphQlClient() {
4749
return GraphQLClient(
48-
cache: GraphQLCache(),
50+
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
4951
link: Link.split(
5052
(request) => request.isSubscription,
5153
websocketLink,

lib/Bloc/config/user_config.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:beacon/Bloc/data/models/user/user_model.dart';
2+
import 'package:beacon/locator.dart';
3+
4+
class UserModelConfig {
5+
UserModel _userModel = UserModel(authToken: 'null');
6+
UserModel get userModel => _userModel;
7+
8+
Future<bool> updateUser(UserModel updateUserDetails) async {
9+
_userModel = updateUserDetails;
10+
return localApi.saveUser(updateUserDetails);
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:geolocator/geolocator.dart';
2+
3+
class LocationService {
4+
static Future<Position> getCurrentLocation() async {
5+
bool serviceEnabled;
6+
LocationPermission permission;
7+
8+
serviceEnabled = await Geolocator.isLocationServiceEnabled();
9+
10+
if (!serviceEnabled) {
11+
return Future.error('Location service is disabled.');
12+
}
13+
14+
permission = await Geolocator.checkPermission();
15+
16+
if (permission == LocationPermission.denied) {
17+
permission = await Geolocator.requestPermission();
18+
if (permission == LocationPermission.denied) {
19+
return Future.error('Location permission is denied');
20+
}
21+
}
22+
23+
if (permission == LocationPermission.deniedForever) {
24+
return Future.error('Location permission is permanently denied.');
25+
}
26+
27+
return await Geolocator.getCurrentPosition(
28+
desiredAccuracy: LocationAccuracy.high);
29+
}
30+
}

lib/Bloc/core/queries/auth.dart

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:developer';
2-
31
class AuthQueries {
42
String registerUser(String? name, String email, String? password) {
53
return '''
@@ -43,7 +41,6 @@ class AuthQueries {
4341
}
4442

4543
String fetchUserInfo() {
46-
log('fetching user info');
4744
return '''
4845
query{
4946
me{
@@ -52,38 +49,9 @@ class AuthQueries {
5249
name
5350
groups{
5451
_id
55-
title
56-
shortcode
57-
leader {
58-
_id
59-
name
60-
}
61-
members {
62-
_id
63-
name
64-
}
65-
beacons{
66-
_id
67-
}
6852
}
6953
beacons{
7054
_id
71-
title
72-
shortcode
73-
leader {
74-
_id
75-
name
76-
}
77-
followers{
78-
_id
79-
name
80-
}
81-
location {
82-
lat
83-
lon
84-
}
85-
startsAt
86-
expiresAt
8755
}
8856
}
8957
}

lib/Bloc/core/queries/group.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
import 'package:graphql_flutter/graphql_flutter.dart';
22

33
class GroupQueries {
4+
String fetchUserGroups(int page, int pageSize) {
5+
return '''
6+
query {
7+
groups(page: $page, pageSize: $pageSize) {
8+
_id
9+
title
10+
shortcode
11+
leader {
12+
_id
13+
name
14+
}
15+
members {
16+
_id
17+
name
18+
}
19+
beacons {
20+
_id
21+
}
22+
}
23+
}
24+
''';
25+
}
26+
427
String createGroup(String? title) {
528
return '''
629
mutation{
@@ -129,6 +152,36 @@ class GroupQueries {
129152
''';
130153
}
131154

155+
String fetchHikes(String groupID, int page, int pageSize) {
156+
return '''
157+
query{
158+
beacons(groupId: "$groupID", page: $page, pageSize: $pageSize){
159+
_id
160+
title
161+
shortcode
162+
leader {
163+
_id
164+
name
165+
}
166+
location{
167+
lat
168+
lon
169+
}
170+
followers {
171+
_id
172+
name
173+
}
174+
group{
175+
_id
176+
}
177+
startsAt
178+
expiresAt
179+
180+
}
181+
}
182+
''';
183+
}
184+
132185
final groupJoinedSubGql = gql(r'''
133186
subscription StreamNewlyJoinedGroups($id: ID!){
134187
groupJoined(id: $id){
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import 'package:graphql/client.dart';
2-
31
abstract class DataState<T> {
42
final T? data;
5-
final OperationException? error;
3+
final String? error;
64

75
const DataState({this.data, this.error});
86
}
@@ -12,5 +10,5 @@ class DataSuccess<T> extends DataState<T> {
1210
}
1311

1412
class DataFailed<T> extends DataState<T> {
15-
const DataFailed(OperationException error) : super(error: error);
13+
const DataFailed(String error) : super(error: error);
1614
}

lib/Bloc/core/services/shared_prefrence_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:shared_preferences/shared_preferences.dart';
33

4-
class SharedPreferencesService {
4+
class SharedPreferenceService {
55
SharedPreferenceService() {
66
init();
77
}

lib/Bloc/core/utils/utils.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:developer';
2+
import 'package:beacon/old/components/utilities/constants.dart';
23
import 'package:connectivity_plus/connectivity_plus.dart';
34
import 'package:flutter/material.dart';
45
import 'package:graphql/client.dart';
@@ -13,7 +14,7 @@ class Utils {
1314
message,
1415
style: TextStyle(color: Colors.black),
1516
),
16-
// backgroundColor: kLightBlue.withOpacity(0.8),
17+
backgroundColor: kLightBlue.withOpacity(0.8),
1718
shape: RoundedRectangleBorder(
1819
borderRadius: BorderRadius.all(
1920
Radius.circular(10),
@@ -40,7 +41,7 @@ class Utils {
4041
}
4142

4243
Future<bool> checkInternetConnectivity() async {
43-
final connectivityResult = await (Connectivity().checkConnectivity());
44+
final connectivityResult = await Connectivity().checkConnectivity();
4445

4546
if (connectivityResult == ConnectivityResult.mobile ||
4647
connectivityResult == ConnectivityResult.wifi ||

lib/old/components/services/validators.dart renamed to lib/Bloc/core/utils/validators.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
class Validator {
2-
static String? validateName(String name) {
3-
if (name.isEmpty) {
2+
static String? validateName(String? name) {
3+
if (name != null && name.isEmpty) {
44
return "Name must not be left blank";
55
}
66
return null;
77
}
88

9-
static String? validateEmail(String email) {
9+
static String? validateEmail(String? email) {
1010
// If email is empty return.
11-
if (email.isEmpty) {
11+
if (email != null && email.isEmpty) {
1212
return "Email must not be left blank";
1313
}
1414
const String pattern =
1515
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$";
1616
final RegExp regex = RegExp(pattern);
17-
if (!regex.hasMatch(email)) {
17+
if (email != null && !regex.hasMatch(email)) {
1818
return 'Please enter a valid Email Address';
1919
}
2020
return null;
2121
}
2222

23-
static String? validatePassword(String password) {
23+
static String? validatePassword(String? password) {
2424
// If password is empty return.
25-
if (password.isEmpty) {
25+
if (password != null && password.isEmpty) {
2626
return "Password must not be left blank";
2727
}
2828
// const String pattern = r'^(?=.*?[0-9])(?=.*?[!@#\$&*%^~.]).{8,}$';
@@ -32,7 +32,7 @@ class Validator {
3232
const String noSpaces = r'^\S+$';
3333
final RegExp noSpaceRegex = RegExp(noSpaces);
3434

35-
if (password.length < 8) {
35+
if (password!.length < 8) {
3636
return "Must be of atleast 8 characters";
3737
}
3838
// if (!regExp.hasMatch(password)) {
@@ -44,33 +44,33 @@ class Validator {
4444
return null;
4545
}
4646

47-
static String? validateBeaconTitle(String title) {
48-
if (title.isEmpty) {
47+
static String? validateBeaconTitle(String? title) {
48+
if (title != null && title.isEmpty) {
4949
return "Title must not be left blank";
5050
}
5151
return null;
5252
}
5353

54-
static String? validatePasskey(String passkey) {
55-
if (passkey.isEmpty) {
54+
static String? validatePasskey(String? passkey) {
55+
if (passkey != null && passkey.isEmpty) {
5656
return "Passkey must not be left blank";
5757
}
5858
const String pattern = r'[A-Z]+';
5959
final RegExp regExp = RegExp(pattern);
60-
if (!regExp.hasMatch(passkey) || passkey.length != 6) {
60+
if (!regExp.hasMatch(passkey!) || passkey.length != 6) {
6161
return "Invalid passkey";
6262
}
6363
return null;
6464
}
6565

66-
static String? validateDuration(String duration) {
67-
if (duration.startsWith("0:00:00.")) {
66+
static String? validateDuration(String? duration) {
67+
if (duration != null && duration.startsWith("0:00:00.")) {
6868
return "Duration cannot be $duration";
6969
}
7070
return null;
7171
}
7272

73-
static String? validateStartingTime(String startTime) {
73+
static String? validateStartingTime(String? startTime) {
7474
print(startTime);
7575
return null;
7676
}

0 commit comments

Comments
 (0)