@@ -11,11 +11,11 @@ import 'package:ht_dashboard/shared/shared.dart';
11
11
import 'package:ht_shared/ht_shared.dart' ;
12
12
import 'package:intl/intl.dart' ;
13
13
14
- /// {@template categories_page }
14
+ /// {@template topics_page }
15
15
/// A page for displaying and managing Topics in a tabular format.
16
16
/// {@endtemplate}
17
17
class TopicPage extends StatefulWidget {
18
- /// {@macro categories_page }
18
+ /// {@macro topics_page }
19
19
const TopicPage ({super .key});
20
20
21
21
@override
@@ -27,7 +27,7 @@ class _TopicPageState extends State<TopicPage> {
27
27
void initState () {
28
28
super .initState ();
29
29
context.read <ContentManagementBloc >().add (
30
- const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
30
+ const LoadTopicsRequested (limit: kDefaultRowsPerPage),
31
31
);
32
32
}
33
33
@@ -38,34 +38,34 @@ class _TopicPageState extends State<TopicPage> {
38
38
padding: const EdgeInsets .all (AppSpacing .lg),
39
39
child: BlocBuilder <ContentManagementBloc , ContentManagementState >(
40
40
builder: (context, state) {
41
- if (state.categoriesStatus == ContentManagementStatus .loading &&
42
- state.categories .isEmpty) {
41
+ if (state.topicsStatus == ContentManagementStatus .loading &&
42
+ state.topics .isEmpty) {
43
43
return LoadingStateWidget (
44
- icon: Icons .category ,
45
- headline: l10n.loadingCategories ,
44
+ icon: Icons .topic ,
45
+ headline: l10n.loadingTopics ,
46
46
subheadline: l10n.pleaseWait,
47
47
);
48
48
}
49
49
50
- if (state.categoriesStatus == ContentManagementStatus .failure) {
50
+ if (state.topicsStatus == ContentManagementStatus .failure) {
51
51
return FailureStateWidget (
52
52
message: state.errorMessage ?? l10n.unknownError,
53
53
onRetry: () => context.read <ContentManagementBloc >().add (
54
- const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
54
+ const LoadTopicsRequested (limit: kDefaultRowsPerPage),
55
55
),
56
56
);
57
57
}
58
58
59
- if (state.categories .isEmpty) {
59
+ if (state.topics .isEmpty) {
60
60
return Center (
61
- child: Text (l10n.noCategoriesFound ),
61
+ child: Text (l10n.noTopicsFound ),
62
62
);
63
63
}
64
64
65
65
return PaginatedDataTable2 (
66
66
columns: [
67
67
DataColumn2 (
68
- label: Text (l10n.categoryName ),
68
+ label: Text (l10n.topicName ),
69
69
size: ColumnSize .L ,
70
70
),
71
71
DataColumn2 (
@@ -84,28 +84,27 @@ class _TopicPageState extends State<TopicPage> {
84
84
],
85
85
source: _TopicsDataSource (
86
86
context: context,
87
- categories: state.categories,
88
- isLoading:
89
- state.categoriesStatus == ContentManagementStatus .loading,
90
- hasMore: state.categoriesHasMore,
87
+ topics: state.topics,
88
+ isLoading: state.topicsStatus == ContentManagementStatus .loading,
89
+ hasMore: state.topicsHasMore,
91
90
l10n: l10n,
92
91
),
93
92
rowsPerPage: kDefaultRowsPerPage,
94
93
availableRowsPerPage: const [kDefaultRowsPerPage],
95
94
onPageChanged: (pageIndex) {
96
95
final newOffset = pageIndex * kDefaultRowsPerPage;
97
- if (newOffset >= state.categories .length &&
98
- state.categoriesHasMore &&
99
- state.categoriesStatus != ContentManagementStatus .loading) {
96
+ if (newOffset >= state.topics .length &&
97
+ state.topicsHasMore &&
98
+ state.topicsStatus != ContentManagementStatus .loading) {
100
99
context.read <ContentManagementBloc >().add (
101
- LoadCategoriesRequested (
102
- startAfterId: state.categoriesCursor ,
100
+ LoadTopicsRequested (
101
+ startAfterId: state.topicsCursor ,
103
102
limit: kDefaultRowsPerPage,
104
103
),
105
104
);
106
105
}
107
106
},
108
- empty: Center (child: Text (l10n.noCategoriesFound )),
107
+ empty: Center (child: Text (l10n.noTopicsFound )),
109
108
showCheckboxColumn: false ,
110
109
showFirstLastButtons: true ,
111
110
fit: FlexFit .tight,
@@ -123,21 +122,21 @@ class _TopicPageState extends State<TopicPage> {
123
122
class _TopicsDataSource extends DataTableSource {
124
123
_TopicsDataSource ({
125
124
required this .context,
126
- required this .categories ,
125
+ required this .topics ,
127
126
required this .isLoading,
128
127
required this .hasMore,
129
128
required this .l10n,
130
129
});
131
130
132
131
final BuildContext context;
133
- final List <Category > categories ;
132
+ final List <Topic > topics ;
134
133
final bool isLoading;
135
134
final bool hasMore;
136
135
final AppLocalizations l10n;
137
136
138
137
@override
139
138
DataRow ? getRow (int index) {
140
- if (index >= categories .length) {
139
+ if (index >= topics .length) {
141
140
// This can happen if hasMore is true and the user is on the last page.
142
141
// If we are loading, show a spinner. Otherwise, we've reached the end.
143
142
if (isLoading) {
@@ -150,25 +149,23 @@ class _TopicsDataSource extends DataTableSource {
150
149
}
151
150
return null ;
152
151
}
153
- final category = categories [index];
152
+ final topic = topics [index];
154
153
return DataRow2 (
155
154
onSelectChanged: (selected) {
156
155
if (selected ?? false ) {
157
156
context.goNamed (
158
- Routes .editCategoryName ,
159
- pathParameters: {'id' : category .id},
157
+ Routes .editTopicName ,
158
+ pathParameters: {'id' : topic .id},
160
159
);
161
160
}
162
161
},
163
162
cells: [
164
- DataCell (Text (category .name)),
165
- DataCell (Text (category .status.l10n (context))),
163
+ DataCell (Text (topic .name)),
164
+ DataCell (Text (topic .status.l10n (context))),
166
165
DataCell (
167
166
Text (
168
- category.updatedAt != null
169
- // TODO(fulleni): Make date format configurable by admin.
170
- ? DateFormat ('dd-MM-yyyy' ).format (category.updatedAt! .toLocal ())
171
- : l10n.notAvailable,
167
+ // TODO(fulleni): Make date format configurable by admin.
168
+ DateFormat ('dd-MM-yyyy' ).format (topic.updatedAt.toLocal ()),
172
169
),
173
170
),
174
171
DataCell (
@@ -179,8 +176,8 @@ class _TopicsDataSource extends DataTableSource {
179
176
onPressed: () {
180
177
// Navigate to edit page
181
178
context.goNamed (
182
- Routes .editCategoryName , // Assuming an edit route exists
183
- pathParameters: {'id' : category .id},
179
+ Routes .editTopicName , // Assuming an edit route exists
180
+ pathParameters: {'id' : topic .id},
184
181
);
185
182
},
186
183
),
@@ -189,7 +186,7 @@ class _TopicsDataSource extends DataTableSource {
189
186
onPressed: () {
190
187
// Dispatch delete event
191
188
context.read <ContentManagementBloc >().add (
192
- DeleteCategoryRequested (category .id),
189
+ DeleteTopicRequested (topic .id),
193
190
);
194
191
},
195
192
),
@@ -211,11 +208,9 @@ class _TopicsDataSource extends DataTableSource {
211
208
if (hasMore) {
212
209
// When loading, we show an extra row for the spinner.
213
210
// Otherwise, we just indicate that there are more rows.
214
- return isLoading
215
- ? categories.length + 1
216
- : categories.length + kDefaultRowsPerPage;
211
+ return isLoading ? topics.length + 1 : topics.length + kDefaultRowsPerPage;
217
212
}
218
- return categories .length;
213
+ return topics .length;
219
214
}
220
215
221
216
@override
0 commit comments