Skip to content

Commit b45bf9c

Browse files
committed
feat(account): display saved headlines list
- Fetches and displays saved headlines - Handles loading, failure and empty states - Allows removing headlines from saved list
1 parent 7172abc commit b45bf9c

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed
Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:ht_main/account/bloc/account_bloc.dart';
5+
import 'package:ht_main/headlines-feed/widgets/headline_item_widget.dart';
26
import 'package:ht_main/l10n/l10n.dart';
7+
import 'package:ht_main/router/routes.dart';
8+
import 'package:ht_main/shared/widgets/widgets.dart';
9+
import 'package:ht_shared/ht_shared.dart' show Headline;
310

411
/// {@template saved_headlines_page}
5-
/// A placeholder page for displaying user's saved headlines.
12+
/// Displays the list of headlines saved by the user.
13+
///
14+
/// Allows users to view details of a saved headline or remove it
15+
/// from their saved list.
616
/// {@endtemplate}
717
class SavedHeadlinesPage extends StatelessWidget {
818
/// {@macro saved_headlines_page}
@@ -11,9 +21,69 @@ class SavedHeadlinesPage extends StatelessWidget {
1121
@override
1222
Widget build(BuildContext context) {
1323
final l10n = context.l10n;
24+
1425
return Scaffold(
1526
appBar: AppBar(title: Text(l10n.accountSavedHeadlinesTile)),
16-
body: const Center(child: Text('SAVED HEADLINES PAGE (Placeholder)')),
27+
body: BlocBuilder<AccountBloc, AccountState>(
28+
builder: (context, state) {
29+
if (state.status == AccountStatus.loading &&
30+
state.preferences == null) {
31+
return LoadingStateWidget(
32+
icon: Icons.bookmarks_outlined,
33+
headline: 'Loading Saved Headlines...', // Placeholder
34+
subheadline: 'Please wait while we fetch your saved articles.', // Placeholder
35+
);
36+
}
37+
38+
if (state.status == AccountStatus.failure &&
39+
state.preferences == null) {
40+
return FailureStateWidget(
41+
message:
42+
state.errorMessage ?? 'Could not load saved headlines.', // Placeholder
43+
onRetry: () {
44+
if (state.user?.id != null) {
45+
context.read<AccountBloc>().add(
46+
AccountLoadContentPreferencesRequested(
47+
userId: state.user!.id,
48+
),
49+
);
50+
}
51+
},
52+
);
53+
}
54+
55+
final savedHeadlines = state.preferences?.savedHeadlines ?? [];
56+
57+
if (savedHeadlines.isEmpty) {
58+
return InitialStateWidget(
59+
icon: Icons.bookmark_add_outlined,
60+
headline: 'No Saved Headlines', // Placeholder
61+
subheadline: 'You haven\'t saved any articles yet. Start exploring!', // Placeholder
62+
);
63+
}
64+
65+
return ListView.separated(
66+
itemCount: savedHeadlines.length,
67+
separatorBuilder: (context, index) => const Divider(height: 1),
68+
itemBuilder: (context, index) {
69+
final headline = savedHeadlines[index];
70+
return HeadlineItemWidget(
71+
headline: headline,
72+
targetRouteName: Routes.accountArticleDetailsName,
73+
trailing: IconButton( // Changed from trailingWidget
74+
icon: const Icon(Icons.delete_outline),
75+
tooltip: 'Remove from saved', // Placeholder
76+
onPressed: () {
77+
context.read<AccountBloc>().add(
78+
AccountSaveHeadlineToggled(headline: headline),
79+
);
80+
},
81+
),
82+
);
83+
},
84+
);
85+
},
86+
),
1787
);
1888
}
1989
}

0 commit comments

Comments
 (0)