1
1
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' ;
2
6
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;
3
10
4
11
/// {@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.
6
16
/// {@endtemplate}
7
17
class SavedHeadlinesPage extends StatelessWidget {
8
18
/// {@macro saved_headlines_page}
@@ -11,9 +21,69 @@ class SavedHeadlinesPage extends StatelessWidget {
11
21
@override
12
22
Widget build (BuildContext context) {
13
23
final l10n = context.l10n;
24
+
14
25
return Scaffold (
15
26
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
+ ),
17
87
);
18
88
}
19
89
}
0 commit comments