Skip to content

Commit 409bb2c

Browse files
committed
feat(account): add content limitation check for following countries
- Implement content limitation service to check if the user can follow more countries - Show a bottom sheet with limitation details when the user reaches the follow limit - Refactor the follow/unfollow logic to incorporate the limitation check - Add necessary imports for the content limitation service and bottom sheet widget
1 parent a6eacab commit 409bb2c

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

lib/account/view/manage_followed_items/countries/add_country_to_follow_page.dart

Lines changed: 45 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_countries_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_country_to_follow_page}
@@ -150,29 +152,61 @@ class AddCountryToFollowPage extends StatelessWidget {
150152
? l10n.unfollowCountryTooltip(country.name)
151153
: l10n.followCountryTooltip(country.name),
152154
onPressed: () {
155+
// Ensure user preferences are available before
156+
// proceeding.
153157
if (userContentPreferences == null) return;
154158

159+
// Create a mutable copy of the followed countries list.
155160
final updatedFollowedCountries = List<Country>.from(
156161
followedCountries,
157162
);
163+
164+
// If the user is unfollowing, always allow it.
158165
if (isFollowed) {
159166
updatedFollowedCountries.removeWhere(
160167
(c) => c.id == country.id,
161168
);
169+
final updatedPreferences = userContentPreferences
170+
.copyWith(
171+
followedCountries: updatedFollowedCountries,
172+
);
173+
174+
context.read<AppBloc>().add(
175+
AppUserContentPreferencesChanged(
176+
preferences: updatedPreferences,
177+
),
178+
);
162179
} else {
163-
updatedFollowedCountries.add(country);
164-
}
180+
// If the user is following, check the limit first.
181+
final limitationService = context
182+
.read<ContentLimitationService>();
183+
final status = limitationService.checkAction(
184+
ContentAction.followCountry,
185+
);
165186

166-
final updatedPreferences = userContentPreferences
167-
.copyWith(
168-
followedCountries: updatedFollowedCountries,
169-
);
187+
if (status == LimitationStatus.allowed) {
188+
updatedFollowedCountries.add(country);
189+
final updatedPreferences =
190+
userContentPreferences.copyWith(
191+
followedCountries:
192+
updatedFollowedCountries,
193+
);
170194

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

0 commit comments

Comments
 (0)