Skip to content

Commit a6eacab

Browse files
committed
feat(account): add content limitation check for following topics
- Implement content limitation service to check if the user can follow more topics - Show a bottom sheet with limitation information when the user reaches the limit - Ensure the app doesn't allow following more topics than the allowed limit
1 parent 6be2c3e commit a6eacab

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

lib/account/view/manage_followed_items/topics/add_topic_to_follow_page.dart

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/available_topics_bloc.dart';
66
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
8+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
9+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
810
import 'package:ui_kit/ui_kit.dart';
911

1012
/// {@template add_topic_to_follow_page}
@@ -149,29 +151,60 @@ class AddTopicToFollowPage extends StatelessWidget {
149151
? l10n.unfollowTopicTooltip(topic.name)
150152
: l10n.followTopicTooltip(topic.name),
151153
onPressed: () {
154+
// Ensure user preferences are available before
155+
// proceeding.
152156
if (userContentPreferences == null) return;
153157

158+
// Create a mutable copy of the followed topics list.
154159
final updatedFollowedTopics = List<Topic>.from(
155160
followedTopics,
156161
);
162+
163+
// If the user is unfollowing, always allow it.
157164
if (isFollowed) {
158165
updatedFollowedTopics.removeWhere(
159166
(t) => t.id == topic.id,
160167
);
168+
final updatedPreferences = userContentPreferences
169+
.copyWith(
170+
followedTopics: updatedFollowedTopics,
171+
);
172+
173+
context.read<AppBloc>().add(
174+
AppUserContentPreferencesChanged(
175+
preferences: updatedPreferences,
176+
),
177+
);
161178
} else {
162-
updatedFollowedTopics.add(topic);
163-
}
179+
// If the user is following, check the limit first.
180+
final limitationService = context
181+
.read<ContentLimitationService>();
182+
final status = limitationService.checkAction(
183+
ContentAction.followTopic,
184+
);
164185

165-
final updatedPreferences = userContentPreferences
166-
.copyWith(
167-
followedTopics: updatedFollowedTopics,
168-
);
186+
if (status == LimitationStatus.allowed) {
187+
updatedFollowedTopics.add(topic);
188+
final updatedPreferences =
189+
userContentPreferences.copyWith(
190+
followedTopics: updatedFollowedTopics,
191+
);
169192

170-
context.read<AppBloc>().add(
171-
AppUserContentPreferencesChanged(
172-
preferences: updatedPreferences,
173-
),
174-
);
193+
context.read<AppBloc>().add(
194+
AppUserContentPreferencesChanged(
195+
preferences: updatedPreferences,
196+
),
197+
);
198+
} else {
199+
// If the limit is reached, show the bottom sheet.
200+
showModalBottomSheet<void>(
201+
context: context,
202+
builder: (_) => ContentLimitationBottomSheet(
203+
status: status,
204+
),
205+
);
206+
}
207+
}
175208
},
176209
),
177210
contentPadding: const EdgeInsets.symmetric(

0 commit comments

Comments
 (0)