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

Fix events for inno23 #214

Merged
merged 18 commits into from
Oct 29, 2023
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
Binary file added elaichi/assets/images/hn_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions elaichi/lib/data/remote/graphql/graphql_service.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// ignore_for_file: avoid_dynamic_calls

import 'package:elaichi/data/constants/app_env.dart';
import 'package:elaichi/data/constants/global_enums.dart';
import 'package:elaichi/data/remote/graphql/mutations.dart';
import 'package:elaichi/data/remote/graphql/queries.dart';
import 'package:elaichi/domain/models/event/event.dart';
import 'package:elaichi/domain/models/event_registration/event_registration.dart';
import 'package:elaichi/domain/models/mm_article/mm_article.dart';
import 'package:elaichi/domain/models/org/org.dart';
import 'package:elaichi/domain/models/user/user.dart';
import 'package:elaichi/presentation/components/toasts/toast_util.dart';
import 'package:flutter/foundation.dart';
import 'package:graphql/client.dart';

Expand Down Expand Up @@ -112,7 +114,14 @@ class GraphQLService {
.map((e) => Event.fromJson(e as Map<String, dynamic>))
.toList();

return events;
final finalEvents = <Event>[];
for (final event in events) {
if (event.status == StatusType.ACTIVE) {
finalEvents.add(event);
}
}

return finalEvents;
} catch (e) {
rethrow;
}
Expand Down Expand Up @@ -143,7 +152,7 @@ class GraphQLService {
final result =
await query(queryString: Queries.getUser, variables: {'uid': uid});

final userList = (result.data!['user'] as List<dynamic>)
final userList = (result.data!["user"]["data"] as List<dynamic>)
.map((e) => User.fromJson(e as Map<String, dynamic>))
.toList();

Expand Down Expand Up @@ -186,7 +195,7 @@ class GraphQLService {
}
}

Future<EventRegistration> createEventRegistration({
Future<EventRegistration?> createEventRegistration({
required String eventID,
required String userID,
}) async {
Expand All @@ -204,7 +213,12 @@ class GraphQLService {
);
return eventRegistration;
} catch (e) {
rethrow;
final toastUtil = ToastUtil.getInstance();
toastUtil.showToast(
mode: ToastMode.Info,
title: 'You have already registerd',
);
return null;
}
}

Expand Down
25 changes: 14 additions & 11 deletions elaichi/lib/data/remote/graphql/queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Queries {
}
''';

static const getOrgs = r'''
query Org ($pagination: paginationInputType, $orgType: OrgType){
org(pagination: $pagination, orgType: $orgType){
static const getOrgs = '''
query Org {
org {
id
name
description
Expand All @@ -42,14 +42,17 @@ class Queries {
static const getUser = r'''
query User($uid: ID) {
user(uid: $uid) {
id
email
uid
name
photo
rollNumber
college
mobile
data {
id
email
uid
name
photo
rollNumber
college
mobile
festID
}
}
}
''';
Expand Down
11 changes: 9 additions & 2 deletions elaichi/lib/domain/repositories/events_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EventRepository {
}
}

Future<Either<CustomException, EventRegistration>> createEventRegistration({
Future<Either<CustomException, EventRegistration?>> createEventRegistration({
required String eventID,
required String userID,
}) async {
Expand Down Expand Up @@ -82,7 +82,14 @@ class EventRepository {
}

Map<String, List<Event>> getCategorisedEvents(List<Event> events) {
final map = <String, List<Event>>{};
final map = <String, List<Event>>{
'TECHNICAL': [],
'PRO': [],
'GUEST-LECTURES': [],
'EXHIBITIONS': [],
'FUN': [],
'WORKSHOP': [],
};

for (final element in events) {
if (map.keys.contains(element.type)) {
Expand Down
10 changes: 7 additions & 3 deletions elaichi/lib/domain/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UserRepository {
}
}

Future<void> getUser() async {
Future<User?> getUser() async {
try {
final user =
await _graphQLService.getUser(_firebaseAuth.currentUser!.uid);
Expand All @@ -86,13 +86,17 @@ class UserRepository {
if (user.rollNumber != null) {
_localStorageService.rollNumber = user.rollNumber;
}
return user;
} catch (e) {
debugPrint(e.toString());
}
return null;
}

Future<void> getOrCreateUser(
{required String rollNumber, required String mobileNumber,}) async {
Future<void> getOrCreateUser({
required String rollNumber,
required String mobileNumber,
}) async {
try {
if (user == null) {
final fbUser = _firebaseAuth.currentUser;
Expand Down
4 changes: 2 additions & 2 deletions elaichi/lib/presentation/browse/browse_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EventCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
jsonDecode(event.name)['subHeading'].toString(),
event.subHeading,
style: interTextTheme.bodyMedium!.copyWith(
fontWeight: FontWeight.w700,
color: AppColors.grey3,
Expand All @@ -78,7 +78,7 @@ class EventCard extends StatelessWidget {
),
const SizedBox(height: 6),
Text(
jsonDecode(event.name)['heading'].toString(),
event.name,
style: interTextTheme.bodyMedium!.copyWith(
fontWeight: FontWeight.w700,
color: AppColors.grey2,
Expand Down
3 changes: 2 additions & 1 deletion elaichi/lib/presentation/core/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class AppRouter {
settings: settings,
builder: (context) => AllEventsPage(
events: map['events'] as Map<String, Map<String, List<Event>>>,
controllIndex: map['index'] as int,
),
);

Expand All @@ -81,7 +82,7 @@ class AppRouter {
return AppPageRoute(
settings: settings,
builder: (context) => const RegistrationDetails(),
);
);
case privacyPolicy:
return AppPageRoute<void>(
settings: settings,
Expand Down
1 change: 1 addition & 0 deletions elaichi/lib/presentation/core/utils/event_type_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Map<String, String> get eventTypeMapping => {
'EXHIBITIONS': 'Exhibitions',
'FUN': 'Fun Events',
'WORKSHOP': 'Workshops',
'OTHER': 'Others',
};
2 changes: 1 addition & 1 deletion elaichi/lib/presentation/core/utils/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Strings {
'https://images.hindustantimes.com/img/2022/06/29/1600x900/NIT_Rourkela_main_entrance_(1)_1656490094321_1656490107321.jpg';
static const String kNitrImage = 'assets/images/nitr.png';
static const String kShaderImage = 'assets/images/shader.png';
static const String hackNITR = 'assets/images/hack_nitr.png';
static const String hackNITR = 'assets/images/hn_title.png';
static const String kStoriesthisWeek = ' Stories this week';
static const String kToday = 'Today';
static const String kViewCalendar = 'View Calendar';
Expand Down
7 changes: 4 additions & 3 deletions elaichi/lib/presentation/core/utils/urlLauncher.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:url_launcher/url_launcher.dart';

launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url, enableJavaScript: true);
void launchURL(String url) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
Expand Down
10 changes: 6 additions & 4 deletions elaichi/lib/presentation/home/fest/bloc/fest_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FestBloc extends Bloc<FestEvent, FestState> {
(event, emit) async {
await event.when(
started: () async {
final status = isVerified();
final status = await isVerified();

final fests = await _eventRepository.getFests();

Expand All @@ -44,8 +44,8 @@ class FestBloc extends Bloc<FestEvent, FestState> {
},
);
},
webMailLogIn: () {
final status = isVerified();
webMailLogIn: () async {
final status = await isVerified();
emit(
(state as _Initial).copyWith(
webMailState: status
Expand Down Expand Up @@ -82,7 +82,9 @@ class FestBloc extends Bloc<FestEvent, FestState> {
}
}

bool isVerified() {
Future<bool> isVerified() async {
final user = await _userRepository.getUser();
if (user == null) return false;
if (_userRepository.rollNumber != null) {
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';

class AllEventsPage extends StatefulWidget {
const AllEventsPage({super.key, required this.events});
const AllEventsPage({
super.key,
required this.events,
required this.controllIndex,
});

final Map<String, Map<String, List<Event>>> events;
final int controllIndex;

@override
State<AllEventsPage> createState() => _AllEventsPageState();
Expand Down Expand Up @@ -46,6 +51,7 @@ class _AllEventsPageState extends State<AllEventsPage> {
setState(() {});
});
_cubit = AllEventsCubit();
_cubit.selectChip(widget.controllIndex);
super.initState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class RegistrationCubit extends Cubit<RegistrationState> {
eventRegistration.fold(
(exception) => emit(RegistrationState.error(error: exception.message!)),
(eventRegistration) async {
eventRegistration ??= EventRegistration(
id: 'abc',
eventID: event.id,
userID: user.id,
);
eventRegistrations.add(eventRegistration);
emit(const RegistrationState.success());
emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ class EventDetailsPage extends StatelessWidget {
Text(
description[index]['desc'].toString(),
style: interTextTheme.bodyLarge!.copyWith(
color: AppColors.grey6.withOpacity(0.8),),
color: AppColors.grey6.withOpacity(0.8),
),
),
const SizedBox(height: 14),
],
Expand Down
Loading