Skip to content

Commit 05963b7

Browse files
committed
feat(account): improve followed sources list
- Refactor UI for clarity - Add loading and error states - Improve navigation - Use shared widgets
1 parent 916b517 commit 05963b7

File tree

1 file changed

+48
-66
lines changed

1 file changed

+48
-66
lines changed

lib/account/view/manage_followed_items/sources/followed_sources_list_page.dart

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
33
import 'package:go_router/go_router.dart';
44
import 'package:ht_main/account/bloc/account_bloc.dart';
5-
import 'package:ht_main/entity_details/view/entity_details_page.dart'; // Added
5+
import 'package:ht_main/entity_details/view/entity_details_page.dart'; // Import for Arguments
66
import 'package:ht_main/l10n/l10n.dart';
77
import 'package:ht_main/router/routes.dart';
8-
import 'package:ht_main/shared/constants/app_spacing.dart';
9-
import 'package:ht_main/shared/widgets/widgets.dart';
8+
import 'package:ht_main/shared/widgets/widgets.dart'; // For common widgets
9+
import 'package:ht_shared/ht_shared.dart';
1010

1111
/// {@template followed_sources_list_page}
12-
/// Displays a list of sources the user is currently following.
13-
/// Allows unfollowing and navigating to add more sources.
12+
/// Page to display and manage sources followed by the user.
1413
/// {@endtemplate}
1514
class FollowedSourcesListPage extends StatelessWidget {
1615
/// {@macro followed_sources_list_page}
@@ -19,14 +18,16 @@ class FollowedSourcesListPage extends StatelessWidget {
1918
@override
2019
Widget build(BuildContext context) {
2120
final l10n = context.l10n;
21+
final followedSources =
22+
context.watch<AccountBloc>().state.preferences?.followedSources ?? [];
2223

2324
return Scaffold(
2425
appBar: AppBar(
25-
title: Text(l10n.followedSourcesPageTitle),
26+
title: const Text('Followed Sources'), // Placeholder
2627
actions: [
2728
IconButton(
2829
icon: const Icon(Icons.add_circle_outline),
29-
tooltip: l10n.addSourcesTooltip,
30+
tooltip: 'Add Source to Follow', // Placeholder
3031
onPressed: () {
3132
context.goNamed(Routes.addSourceToFollowName);
3233
},
@@ -35,87 +36,68 @@ class FollowedSourcesListPage extends StatelessWidget {
3536
),
3637
body: BlocBuilder<AccountBloc, AccountState>(
3738
builder: (context, state) {
38-
if (state.status == AccountStatus.initial ||
39-
(state.status == AccountStatus.loading &&
40-
state.preferences == null)) {
41-
return const Center(child: CircularProgressIndicator());
39+
if (state.status == AccountStatus.loading &&
40+
state.preferences == null) {
41+
return LoadingStateWidget(
42+
icon: Icons.source_outlined,
43+
headline: 'Loading Followed Sources...', // Placeholder
44+
subheadline: l10n.pleaseWait, // Assuming this exists
45+
);
4246
}
4347

4448
if (state.status == AccountStatus.failure &&
4549
state.preferences == null) {
4650
return FailureStateWidget(
47-
message: state.errorMessage ?? l10n.unknownError,
51+
message: state.errorMessage ?? 'Could not load followed sources.', // Placeholder
4852
onRetry: () {
4953
if (state.user?.id != null) {
5054
context.read<AccountBloc>().add(
51-
AccountLoadContentPreferencesRequested(
52-
userId: state.user!.id,
53-
),
54-
);
55+
AccountLoadUserPreferences( // Corrected event name
56+
userId: state.user!.id,
57+
),
58+
);
5559
}
5660
},
5761
);
5862
}
5963

60-
final followedSources = state.preferences?.followedSources;
61-
62-
if (followedSources == null || followedSources.isEmpty) {
63-
return Center(
64-
child: Padding(
65-
padding: const EdgeInsets.all(AppSpacing.lg),
66-
child: Column(
67-
mainAxisAlignment: MainAxisAlignment.center,
68-
children: [
69-
const Icon(Icons.source_outlined, size: 48),
70-
const SizedBox(height: AppSpacing.md),
71-
Text(
72-
l10n.noFollowedSourcesMessage,
73-
style: Theme.of(context).textTheme.titleMedium,
74-
textAlign: TextAlign.center,
75-
),
76-
const SizedBox(height: AppSpacing.lg),
77-
ElevatedButton.icon(
78-
icon: const Icon(Icons.add_circle_outline),
79-
label: Text(l10n.addSourcesButtonLabel),
80-
onPressed: () {
81-
context.goNamed(Routes.addSourceToFollowName);
82-
},
83-
),
84-
],
85-
),
86-
),
64+
if (followedSources.isEmpty) {
65+
return const InitialStateWidget(
66+
icon: Icons.no_sim_outlined, // Placeholder icon
67+
headline: 'No Followed Sources', // Placeholder
68+
subheadline: 'Start following sources to see them here.', // Placeholder
8769
);
8870
}
8971

9072
return ListView.builder(
91-
padding: const EdgeInsets.all(AppSpacing.md),
9273
itemCount: followedSources.length,
9374
itemBuilder: (context, index) {
9475
final source = followedSources[index];
95-
return Card(
96-
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
97-
child: ListTile(
98-
title: Text(source.name),
99-
onTap: () {
100-
// Added onTap for navigation
101-
context.push(
102-
Routes.sourceDetails,
103-
extra: EntityDetailsPageArguments(entity: source),
104-
);
76+
return ListTile(
77+
leading: const Icon(Icons.source_outlined), // Generic icon
78+
title: Text(source.name),
79+
subtitle: source.description != null
80+
? Text(
81+
source.description!,
82+
maxLines: 1,
83+
overflow: TextOverflow.ellipsis,
84+
)
85+
: null,
86+
trailing: IconButton(
87+
icon: const Icon(Icons.remove_circle_outline, color: Colors.red),
88+
tooltip: 'Unfollow Source', // Placeholder
89+
onPressed: () {
90+
context.read<AccountBloc>().add(
91+
AccountFollowSourceToggled(source: source),
92+
);
10593
},
106-
trailing: IconButton(
107-
icon: Icon(
108-
Icons.remove_circle_outline,
109-
color: Theme.of(context).colorScheme.error,
110-
),
111-
tooltip: l10n.unfollowSourceTooltip(source.name),
112-
onPressed: () {
113-
context.read<AccountBloc>().add(
114-
AccountFollowSourceToggled(source: source),
115-
);
116-
},
117-
),
11894
),
95+
onTap: () {
96+
context.push(
97+
Routes.sourceDetails, // Navigate to source details
98+
extra: EntityDetailsPageArguments(entity: source),
99+
);
100+
},
119101
);
120102
},
121103
);

0 commit comments

Comments
 (0)