Skip to content

Commit 04f260e

Browse files
committed
refactor(feed_decorators): simplify content collection follow logic
Refactors `ContentCollectionDecoratorWidget` to correctly delegate the `onFollowToggle` action to its parent widget. The widget was incorrectly re-implementing the follow/unfollow logic inline, ignoring the `onFollowToggle` callback passed to its constructor. This change removes the redundant logic and correctly calls `widget.onFollowToggle`, restoring the intended separation of concerns where the parent (`FeedDecoratorLoaderWidget`) is responsible for handling the action.
1 parent 345e298 commit 04f260e

File tree

1 file changed

+1
-45
lines changed

1 file changed

+1
-45
lines changed

lib/feed_decorators/widgets/content_collection_decorator_widget.dart

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -162,51 +162,7 @@ class _ContentCollectionViewState extends State<_ContentCollectionView> {
162162
followedSourceIds.contains(suggestion.id));
163163
return SuggestionItemWidget(
164164
item: suggestion,
165-
onFollowToggle: (toggledItem) {
166-
final currentUserPreferences =
167-
appState.userContentPreferences;
168-
if (currentUserPreferences == null) return;
169-
170-
UserContentPreferences updatedPreferences;
171-
172-
if (toggledItem is Topic) {
173-
final followedTopics = List<Topic>.from(
174-
currentUserPreferences.followedTopics,
175-
);
176-
if (isFollowing) {
177-
followedTopics.removeWhere(
178-
(topic) => topic.id == toggledItem.id,
179-
);
180-
} else {
181-
followedTopics.add(toggledItem);
182-
}
183-
updatedPreferences = currentUserPreferences.copyWith(
184-
followedTopics: followedTopics,
185-
);
186-
} else if (toggledItem is Source) {
187-
final followedSources = List<Source>.from(
188-
currentUserPreferences.followedSources,
189-
);
190-
if (isFollowing) {
191-
followedSources.removeWhere(
192-
(source) => source.id == toggledItem.id,
193-
);
194-
} else {
195-
followedSources.add(toggledItem);
196-
}
197-
updatedPreferences = currentUserPreferences.copyWith(
198-
followedSources: followedSources,
199-
);
200-
} else {
201-
return;
202-
}
203-
204-
context.read<AppBloc>().add(
205-
AppUserContentPreferencesChanged(
206-
preferences: updatedPreferences,
207-
),
208-
);
209-
},
165+
onFollowToggle: widget.onFollowToggle,
210166
isFollowing: isFollowing,
211167
);
212168
},

0 commit comments

Comments
 (0)