@@ -54,10 +54,6 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
5454 _onFeedDecoratorDismissed,
5555 transformer: sequential (),
5656 );
57- on < SuggestedItemFollowToggled > (
58- _onSuggestedItemFollowToggled,
59- transformer: sequential (),
60- );
6157 on < CallToActionTapped > (_onCallToActionTapped, transformer: sequential ());
6258 on < NavigationHandled > (_onNavigationHandled, transformer: sequential ());
6359 }
@@ -393,74 +389,6 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
393389 emit (state.copyWith (feedItems: newFeedItems));
394390 }
395391
396- /// Handles the toggling of follow status for a suggested topic or source.
397- ///
398- /// Updates the user's content preferences in the repository.
399- Future <void > _onSuggestedItemFollowToggled (
400- SuggestedItemFollowToggled event,
401- Emitter <HeadlinesFeedState > emit,
402- ) async {
403- final currentUser = _appBloc.state.user;
404- if (currentUser == null ) return ;
405-
406- try {
407- // Fetch current user preferences
408- final currentPreferences = await _userContentPreferencesRepository.read (
409- id: currentUser.id,
410- userId: currentUser.id,
411- );
412-
413- UserContentPreferences updatedPreferences;
414- if (event.item is Topic ) {
415- final topic = event.item as Topic ;
416- final currentTopics = List <Topic >.from (
417- currentPreferences.followedTopics,
418- );
419- if (event.isFollowing) {
420- currentTopics.add (topic);
421- } else {
422- currentTopics.removeWhere ((t) => t.id == topic.id);
423- }
424- updatedPreferences = currentPreferences.copyWith (
425- followedTopics: currentTopics,
426- );
427- } else if (event.item is Source ) {
428- final source = event.item as Source ;
429- final currentSources = List <Source >.from (
430- currentPreferences.followedSources,
431- );
432- if (event.isFollowing) {
433- currentSources.add (source);
434- } else {
435- currentSources.removeWhere ((s) => s.id == source.id);
436- }
437- updatedPreferences = currentPreferences.copyWith (
438- followedSources: currentSources,
439- );
440- } else {
441- // Should not happen given the event's item type constraint
442- return ;
443- }
444-
445- // Persist updated preferences
446- await _userContentPreferencesRepository.update (
447- id: updatedPreferences.id,
448- item: updatedPreferences,
449- userId: updatedPreferences.id,
450- );
451-
452- // After persisting the change, emit a state copy to trigger a UI
453- // rebuild. The UI will then get the latest follow status from the
454- // updated AccountBloc state.
455- emit (state.copyWith ());
456- } on HttpException catch (e) {
457- // Handle error, e.g., show a snackbar or log
458- print ('Error toggling follow status: $e ' );
459- // Emit a failure state if necessary, but for a minor interaction,
460- // logging might be sufficient.
461- }
462- }
463-
464392 /// Handles a tap on a call-to-action decorator.
465393 ///
466394 /// This typically involves navigating to an external URL or an internal route.
0 commit comments