Skip to content

Commit 914f333

Browse files
committed
feat(entity_details): implement content limitation check for follow actions
- Add ContentLimitationService import and usage in EntityDetailsView - Implement logic to check content limitation before allowing follow actions - Display ContentLimitationBottomSheet when action is limited - Update follow button onPressed logic to handle both following and unfollowing cases
1 parent f541d0a commit 914f333

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

lib/entity_details/view/entity_details_page.dart

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/b
1212
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
1313
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
1414
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
15+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
16+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
1517
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/feed_core/feed_core.dart';
1618
import 'package:go_router/go_router.dart';
1719
import 'package:ui_kit/ui_kit.dart';
@@ -165,9 +167,45 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
165167
? l10n.unfollowButtonLabel
166168
: l10n.followButtonLabel,
167169
onPressed: () {
168-
context.read<EntityDetailsBloc>().add(
169-
const EntityDetailsToggleFollowRequested(),
170-
);
170+
// If the user is unfollowing, always allow it.
171+
if (state.isFollowing) {
172+
context.read<EntityDetailsBloc>().add(
173+
const EntityDetailsToggleFollowRequested(),
174+
);
175+
} else {
176+
// If the user is following, check the limit first.
177+
final limitationService = context
178+
.read<ContentLimitationService>();
179+
final contentType = state.contentType;
180+
181+
if (contentType == null) return;
182+
183+
final ContentAction action;
184+
switch (contentType) {
185+
case ContentType.topic:
186+
action = ContentAction.followTopic;
187+
case ContentType.source:
188+
action = ContentAction.followSource;
189+
case ContentType.country:
190+
action = ContentAction.followCountry;
191+
case ContentType.headline:
192+
return;
193+
}
194+
195+
final status = limitationService.checkAction(action);
196+
197+
if (status == LimitationStatus.allowed) {
198+
context.read<EntityDetailsBloc>().add(
199+
const EntityDetailsToggleFollowRequested(),
200+
);
201+
} else {
202+
showModalBottomSheet<void>(
203+
context: context,
204+
builder: (_) =>
205+
ContentLimitationBottomSheet(status: status),
206+
);
207+
}
208+
}
171209
},
172210
);
173211

0 commit comments

Comments
 (0)