@@ -4,9 +4,12 @@ import 'package:freezed_annotation/freezed_annotation.dart';
44
55import '../../../data/constants/strings.dart' ;
66import '../../../data/services/local/storage_service.dart' ;
7+ import '../../../data/services/remote/notification_service.dart' ;
78import '../../../domain/models/contest.dart' ;
89import '../../../domain/models/contest_filter.dart' ;
10+ import '../../../domain/models/status.dart' ;
911import '../../../domain/repositories/cp_repository.dart' ;
12+ import '../../../utils/snackbar.dart' ;
1013
1114part 'contests_event.dart' ;
1215part 'contests_state.dart' ;
@@ -21,14 +24,22 @@ class ContestsBloc extends Bloc<ContestsEvent, ContestsState> {
2124 }
2225
2326 void _fetchContests (FetchContests event, Emitter <ContestsState > emit) async {
24- final contest = await CPRepository .contestList ();
27+ Contest ? contest;
28+ try {
29+ contest = await CPRepository .contestList ();
30+ } on Exception catch (_) {
31+ showSnackBar (message: AppStrings .genericError);
32+ emit (state.copyWith (status: const Status .error (AppStrings .genericError)));
33+ return ;
34+ }
35+
2536 _ongoing = [...? contest? .ongoing];
2637 _upcoming = [...? contest? .upcoming];
2738 applyFilter ();
2839 final contests = [..._filteredUpcoming, ..._filteredOngoing];
2940 emit (state.copyWith (
3041 contests: contests,
31- isLoading : false ,
42+ status : const Status () ,
3243 filter: _filter,
3344 ));
3445 }
@@ -92,8 +103,9 @@ class ContestsBloc extends Bloc<ContestsEvent, ContestsState> {
92103 ContestFilter ? _filter;
93104 List <Ongoing > _ongoing = [], _filteredOngoing = [];
94105 List <Upcoming > _upcoming = [], _filteredUpcoming = [];
106+ List <String ?> pendingNotification = [];
95107
96- void init () {
108+ void init () async {
97109 final exists = StorageService .exists (AppStrings .filterKey);
98110 if (! exists) {
99111 StorageService .filter = ContestFilter (
@@ -106,9 +118,14 @@ class ContestsBloc extends Bloc<ContestsEvent, ContestsState> {
106118 }
107119
108120 _filter = StorageService .filter;
121+ pendingNotification = await NotificationService .getPendingNotification ();
109122 add (const FetchContests ());
110123 }
111124
125+ bool reminderSet (String ? title) {
126+ return pendingNotification.contains (title);
127+ }
128+
112129 void saveFilter () {
113130 StorageService .filter = _filter;
114131 add (const UpdateContestsList ());
0 commit comments