Skip to content

Commit 1b57db8

Browse files
committed
fix(feed_decorators): resolve content collection follow/unfollow logic
Fixes a compilation error in `ContentCollectionDecoratorWidget` caused by attempting to call non-existent toggle methods on the immutable `UserContentPreferences` model. The follow/unfollow logic is now handled directly within the widget. It correctly creates a new list of followed items (topics or sources) and uses the `copyWith` method to generate an updated `UserContentPreferences` object before dispatching it to the `AppBloc`. This approach is robust and respects the immutability of the core data model.
1 parent 8222a29 commit 1b57db8

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

lib/feed_decorators/widgets/content_collection_decorator_widget.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,33 @@ class _ContentCollectionViewState extends State<_ContentCollectionView> {
170170
UserContentPreferences updatedPreferences;
171171

172172
if (toggledItem is Topic) {
173-
updatedPreferences = currentUserPreferences
174-
.toggleFollowedTopic(toggledItem);
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+
);
175186
} else if (toggledItem is Source) {
176-
updatedPreferences = currentUserPreferences
177-
.toggleFollowedSource(toggledItem);
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+
);
178200
} else {
179201
return;
180202
}

0 commit comments

Comments
 (0)