Skip to content

Commit b181419

Browse files
committed
feat(account): Manage followed categories
- Display followed categories - Allows unfollowing categories - Navigates to add more categories
1 parent 91e022c commit b181419

File tree

1 file changed

+58
-81
lines changed

1 file changed

+58
-81
lines changed

lib/account/view/manage_followed_items/categories/followed_categories_list_page.dart

Lines changed: 58 additions & 81 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';
98
import 'package:ht_main/shared/widgets/widgets.dart';
9+
import 'package:ht_shared/ht_shared.dart';
1010

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

2325
return Scaffold(
2426
appBar: AppBar(
25-
title: Text(l10n.followedCategoriesPageTitle),
27+
title: const Text('Followed Categories'), // Placeholder
2628
actions: [
2729
IconButton(
2830
icon: const Icon(Icons.add_circle_outline),
29-
tooltip: l10n.addCategoriesTooltip,
31+
tooltip: 'Add Category to Follow', // Placeholder
3032
onPressed: () {
3133
context.goNamed(Routes.addCategoryToFollowName);
3234
},
@@ -35,103 +37,78 @@ class FollowedCategoriesListPage extends StatelessWidget {
3537
),
3638
body: BlocBuilder<AccountBloc, AccountState>(
3739
builder: (context, state) {
38-
if (state.status == AccountStatus.initial ||
39-
(state.status == AccountStatus.loading &&
40-
state.preferences == null)) {
41-
return const Center(child: CircularProgressIndicator());
40+
if (state.status == AccountStatus.loading &&
41+
state.preferences == null) {
42+
return LoadingStateWidget(
43+
icon: Icons.category_outlined,
44+
headline: 'Loading Followed Categories...', // Placeholder
45+
subheadline: l10n.pleaseWait, // Assuming this exists
46+
);
4247
}
4348

4449
if (state.status == AccountStatus.failure &&
4550
state.preferences == null) {
4651
return FailureStateWidget(
47-
message: state.errorMessage ?? l10n.unknownError,
52+
message: state.errorMessage ?? 'Could not load followed categories.', // Placeholder
4853
onRetry: () {
4954
if (state.user?.id != null) {
5055
context.read<AccountBloc>().add(
51-
AccountLoadContentPreferencesRequested(
52-
userId: state.user!.id,
53-
),
54-
);
56+
AccountLoadUserPreferences(
57+
userId: state.user!.id,
58+
),
59+
);
5560
}
5661
},
5762
);
5863
}
5964

60-
final followedCategories = state.preferences?.followedCategories;
61-
62-
if (followedCategories == null || followedCategories.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.category_outlined, size: 48),
70-
const SizedBox(height: AppSpacing.md),
71-
Text(
72-
l10n.noFollowedCategoriesMessage,
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.addCategoriesButtonLabel),
80-
onPressed: () {
81-
context.goNamed(Routes.addCategoryToFollowName);
82-
},
83-
),
84-
],
85-
),
86-
),
65+
if (followedCategories.isEmpty) {
66+
return const InitialStateWidget(
67+
icon: Icons.no_sim_outlined, // Placeholder icon
68+
headline: 'No Followed Categories', // Placeholder
69+
subheadline: 'Start following categories to see them here.', // Placeholder
8770
);
8871
}
8972

9073
return ListView.builder(
91-
padding: const EdgeInsets.all(AppSpacing.md),
9274
itemCount: followedCategories.length,
9375
itemBuilder: (context, index) {
9476
final category = followedCategories[index];
95-
return Card(
96-
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
97-
child: ListTile(
98-
leading:
99-
category.iconUrl != null &&
100-
Uri.tryParse(category.iconUrl!)?.isAbsolute ==
101-
true
102-
? SizedBox(
103-
width: 36,
104-
height: 36,
105-
child: Image.network(
106-
category.iconUrl!,
107-
fit: BoxFit.contain,
108-
errorBuilder:
109-
(context, error, stackTrace) =>
110-
const Icon(Icons.category_outlined),
111-
),
112-
)
113-
: const Icon(Icons.category_outlined),
114-
title: Text(category.name),
115-
onTap: () {
116-
// Added onTap for navigation
117-
context.push(
118-
Routes.categoryDetails,
119-
extra: EntityDetailsPageArguments(entity: category),
120-
);
77+
return ListTile(
78+
leading: category.iconUrl != null
79+
? SizedBox(
80+
width: 40,
81+
height: 40,
82+
child: Image.network(
83+
category.iconUrl!,
84+
errorBuilder: (context, error, stackTrace) =>
85+
const Icon(Icons.category_outlined),
86+
),
87+
)
88+
: const Icon(Icons.category_outlined),
89+
title: Text(category.name),
90+
subtitle: category.description != null
91+
? Text(
92+
category.description!,
93+
maxLines: 1,
94+
overflow: TextOverflow.ellipsis,
95+
)
96+
: null,
97+
trailing: IconButton(
98+
icon: const Icon(Icons.remove_circle_outline, color: Colors.red),
99+
tooltip: 'Unfollow Category', // Placeholder
100+
onPressed: () {
101+
context.read<AccountBloc>().add(
102+
AccountFollowCategoryToggled(category: category),
103+
);
121104
},
122-
trailing: IconButton(
123-
icon: Icon(
124-
Icons.remove_circle_outline,
125-
color: Theme.of(context).colorScheme.error,
126-
),
127-
tooltip: l10n.unfollowCategoryTooltip(category.name),
128-
onPressed: () {
129-
context.read<AccountBloc>().add(
130-
AccountFollowCategoryToggled(category: category),
131-
);
132-
},
133-
),
134105
),
106+
onTap: () {
107+
context.push(
108+
Routes.categoryDetails,
109+
extra: EntityDetailsPageArguments(entity: category),
110+
);
111+
},
135112
);
136113
},
137114
);

0 commit comments

Comments
 (0)