Skip to content

Commit 8268dc2

Browse files
committed
feat(feed_decorators): complete logic in decorator loader
Updates `FeedDecoratorLoaderWidget` to fully implement the decorator loading logic. - Adds the missing implementation to handle the `suggestedSources` decorator type, including fetching sources from the repository and filtering out already-followed items. - Expands the `callToAction` logic to include all CTA types, making the widget feature-complete. - Adds logging for unhandled decorator types to improve maintainability.
1 parent 7372cd8 commit 8268dc2

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

lib/feed_decorators/widgets/feed_decorator_loader_widget.dart

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,11 @@ class _FeedDecoratorLoaderWidgetState extends State<FeedDecoratorLoaderWidget> {
224224
FeedDecoratorConfig decoratorConfig,
225225
) async {
226226
// This logic is a simplified version of the original service, as the
227-
// content is now hardcoded for CTAs.
227+
// content for CTAs is defined statically.
228228
switch (decoratorConfig.category) {
229229
case FeedDecoratorCategory.callToAction:
230+
// A map of static content for different call-to-action types.
231+
// TODO(fulleni): random l10n selection for each type.
230232
const ctaContent = {
231233
FeedDecoratorType.linkAccount: (
232234
title: 'Create an Account',
@@ -235,6 +237,25 @@ class _FeedDecoratorLoaderWidgetState extends State<FeedDecoratorLoaderWidget> {
235237
ctaText: 'Get Started',
236238
ctaUrl: Routes.accountLinking,
237239
),
240+
FeedDecoratorType.upgrade: (
241+
title: 'Upgrade to Premium',
242+
description: 'Unlock unlimited access to all features and content.',
243+
ctaText: 'Upgrade Now',
244+
ctaUrl: '/upgrade',
245+
),
246+
FeedDecoratorType.rateApp: (
247+
title: 'Enjoying the App?',
248+
description: 'Let us know what you think by leaving a rating.',
249+
ctaText: 'Rate App',
250+
ctaUrl: '/rate-app',
251+
),
252+
FeedDecoratorType.enableNotifications: (
253+
title: 'Stay Up to Date',
254+
description:
255+
'Enable notifications to get the latest headlines delivered to you.',
256+
ctaText: 'Enable',
257+
ctaUrl: '/enable-notifications',
258+
),
238259
};
239260
final content = ctaContent[decoratorType];
240261
if (content == null) return null;
@@ -277,8 +298,29 @@ class _FeedDecoratorLoaderWidgetState extends State<FeedDecoratorLoaderWidget> {
277298
title: 'Suggested Topics',
278299
items: topics.items,
279300
);
280-
// Other content collection cases would go here.
301+
case FeedDecoratorType.suggestedSources:
302+
final sources = await context
303+
.read<DataRepository<Source>>()
304+
.readAll(
305+
pagination: PaginationOptions(limit: itemsToDisplay),
306+
sort: [const SortOption('name', SortOrder.asc)],
307+
filter: {
308+
'_id': {r'$nin': followedSourceIds},
309+
'status': ContentStatus.active.name,
310+
},
311+
);
312+
if (sources.items.isEmpty) return null;
313+
return ContentCollectionItem<Source>(
314+
id: _uuid.v4(),
315+
decoratorType: decoratorType,
316+
title: 'Suggested Sources',
317+
items: sources.items,
318+
);
319+
// ignore: no_default_cases
281320
default:
321+
_logger.warning(
322+
'Unhandled ContentCollection decorator type: $decoratorType',
323+
);
282324
return null;
283325
}
284326
}

0 commit comments

Comments
 (0)