Skip to content

Commit f541d0a

Browse files
committed
feat(headline-details): implement content limitation for bookmarking headlines
- Add check for maximum saved headlines before allowing a new save - Show content limitation bottom sheet when save limit is reached - Always allow un-saving headlines without limitation check - Import necessary services and widgets for content limitation functionality
1 parent 3c1ec73 commit f541d0a

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

lib/headline-details/view/headline_details_page.dart

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/headline-details
1313
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/bloc/similar_headlines_bloc.dart';
1414
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
1515
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
16+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
17+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
1618
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/feed_core/feed_core.dart';
1719
import 'package:go_router/go_router.dart';
1820
import 'package:intl/intl.dart';
@@ -198,23 +200,42 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
198200
return;
199201
}
200202

201-
final List<Headline> updatedSavedHeadlines;
203+
// If the user is un-saving, always allow it.
202204
if (isSaved) {
203-
updatedSavedHeadlines = currentPreferences.savedHeadlines
205+
final updatedSavedHeadlines = currentPreferences.savedHeadlines
204206
.where((h) => h.id != headline.id)
205207
.toList();
208+
final updatedPreferences = currentPreferences.copyWith(
209+
savedHeadlines: updatedSavedHeadlines,
210+
);
211+
context.read<AppBloc>().add(
212+
AppUserContentPreferencesChanged(preferences: updatedPreferences),
213+
);
206214
} else {
207-
updatedSavedHeadlines = List.from(currentPreferences.savedHeadlines)
208-
..add(headline);
209-
}
210-
211-
final updatedPreferences = currentPreferences.copyWith(
212-
savedHeadlines: updatedSavedHeadlines,
213-
);
215+
// If the user is saving, check the limit first.
216+
final limitationService = context.read<ContentLimitationService>();
217+
final status = limitationService.checkAction(
218+
ContentAction.bookmarkHeadline,
219+
);
214220

215-
context.read<AppBloc>().add(
216-
AppUserContentPreferencesChanged(preferences: updatedPreferences),
217-
);
221+
if (status == LimitationStatus.allowed) {
222+
final updatedSavedHeadlines = List<Headline>.from(
223+
currentPreferences.savedHeadlines,
224+
)..add(headline);
225+
final updatedPreferences = currentPreferences.copyWith(
226+
savedHeadlines: updatedSavedHeadlines,
227+
);
228+
context.read<AppBloc>().add(
229+
AppUserContentPreferencesChanged(preferences: updatedPreferences),
230+
);
231+
} else {
232+
// If the limit is reached, show the bottom sheet.
233+
showModalBottomSheet<void>(
234+
context: context,
235+
builder: (_) => ContentLimitationBottomSheet(status: status),
236+
);
237+
}
238+
}
218239
},
219240
);
220241

0 commit comments

Comments
 (0)