Skip to content

Commit 2fcfb21

Browse files
committed
fix(content_management): remove loading row from topics table
- Remove loading row from PaginatedDataTable2 - Add LinearProgressIndicator for loading state - Adjust row count logic to remove extra row for loading state - Update TopicsDataSource to remove loading row handling
1 parent 2853886 commit 2fcfb21

File tree

1 file changed

+59
-67
lines changed

1 file changed

+59
-67
lines changed

lib/content_management/view/topics_page.dart

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class _TopicPageState extends State<TopicPage> {
2727
void initState() {
2828
super.initState();
2929
context.read<ContentManagementBloc>().add(
30-
const LoadTopicsRequested(limit: kDefaultRowsPerPage),
31-
);
30+
const LoadTopicsRequested(limit: kDefaultRowsPerPage),
31+
);
3232
}
3333

3434
@override
@@ -51,56 +51,70 @@ class _TopicPageState extends State<TopicPage> {
5151
return FailureStateWidget(
5252
exception: state.exception!,
5353
onRetry: () => context.read<ContentManagementBloc>().add(
54-
const LoadTopicsRequested(limit: kDefaultRowsPerPage),
55-
),
54+
const LoadTopicsRequested(limit: kDefaultRowsPerPage),
55+
),
5656
);
5757
}
5858

5959
if (state.topics.isEmpty) {
6060
return Center(child: Text(l10n.noTopicsFound));
6161
}
6262

63-
return PaginatedDataTable2(
64-
columns: [
65-
DataColumn2(label: Text(l10n.topicName), size: ColumnSize.L),
66-
DataColumn2(label: Text(l10n.status), size: ColumnSize.S),
67-
DataColumn2(label: Text(l10n.lastUpdated), size: ColumnSize.M),
68-
DataColumn2(
69-
label: Text(l10n.actions),
70-
size: ColumnSize.S,
71-
fixedWidth: 120,
63+
return Column(
64+
children: [
65+
if (state.topicsStatus == ContentManagementStatus.loading &&
66+
state.topics.isNotEmpty)
67+
const LinearProgressIndicator(),
68+
Expanded(
69+
child: PaginatedDataTable2(
70+
columns: [
71+
DataColumn2(
72+
label: Text(l10n.topicName),
73+
size: ColumnSize.L,
74+
),
75+
DataColumn2(label: Text(l10n.status), size: ColumnSize.S),
76+
DataColumn2(
77+
label: Text(l10n.lastUpdated),
78+
size: ColumnSize.M,
79+
),
80+
DataColumn2(
81+
label: Text(l10n.actions),
82+
size: ColumnSize.S,
83+
fixedWidth: 120,
84+
),
85+
],
86+
source: _TopicsDataSource(
87+
context: context,
88+
topics: state.topics,
89+
hasMore: state.topicsHasMore,
90+
l10n: l10n,
91+
),
92+
rowsPerPage: kDefaultRowsPerPage,
93+
availableRowsPerPage: const [kDefaultRowsPerPage],
94+
onPageChanged: (pageIndex) {
95+
final newOffset = pageIndex * kDefaultRowsPerPage;
96+
if (newOffset >= state.topics.length &&
97+
state.topicsHasMore &&
98+
state.topicsStatus != ContentManagementStatus.loading) {
99+
context.read<ContentManagementBloc>().add(
100+
LoadTopicsRequested(
101+
startAfterId: state.topicsCursor,
102+
limit: kDefaultRowsPerPage,
103+
),
104+
);
105+
}
106+
},
107+
empty: Center(child: Text(l10n.noTopicsFound)),
108+
showCheckboxColumn: false,
109+
showFirstLastButtons: true,
110+
fit: FlexFit.tight,
111+
headingRowHeight: 56,
112+
dataRowHeight: 56,
113+
columnSpacing: AppSpacing.md,
114+
horizontalMargin: AppSpacing.md,
115+
),
72116
),
73117
],
74-
source: _TopicsDataSource(
75-
context: context,
76-
topics: state.topics,
77-
isLoading: state.topicsStatus == ContentManagementStatus.loading,
78-
hasMore: state.topicsHasMore,
79-
l10n: l10n,
80-
),
81-
rowsPerPage: kDefaultRowsPerPage,
82-
availableRowsPerPage: const [kDefaultRowsPerPage],
83-
onPageChanged: (pageIndex) {
84-
final newOffset = pageIndex * kDefaultRowsPerPage;
85-
if (newOffset >= state.topics.length &&
86-
state.topicsHasMore &&
87-
state.topicsStatus != ContentManagementStatus.loading) {
88-
context.read<ContentManagementBloc>().add(
89-
LoadTopicsRequested(
90-
startAfterId: state.topicsCursor,
91-
limit: kDefaultRowsPerPage,
92-
),
93-
);
94-
}
95-
},
96-
empty: Center(child: Text(l10n.noTopicsFound)),
97-
showCheckboxColumn: false,
98-
showFirstLastButtons: true,
99-
fit: FlexFit.tight,
100-
headingRowHeight: 56,
101-
dataRowHeight: 56,
102-
columnSpacing: AppSpacing.md,
103-
horizontalMargin: AppSpacing.md,
104118
);
105119
},
106120
),
@@ -112,30 +126,18 @@ class _TopicsDataSource extends DataTableSource {
112126
_TopicsDataSource({
113127
required this.context,
114128
required this.topics,
115-
required this.isLoading,
116129
required this.hasMore,
117130
required this.l10n,
118131
});
119132

120133
final BuildContext context;
121134
final List<Topic> topics;
122-
final bool isLoading;
123135
final bool hasMore;
124136
final AppLocalizations l10n;
125137

126138
@override
127139
DataRow? getRow(int index) {
128140
if (index >= topics.length) {
129-
// This can happen if hasMore is true and the user is on the last page.
130-
// If we are loading, show a spinner. Otherwise, we've reached the end.
131-
if (isLoading) {
132-
return DataRow2(
133-
cells: List.generate(
134-
4,
135-
(_) => const DataCell(Center(child: CircularProgressIndicator())),
136-
),
137-
);
138-
}
139141
return null;
140142
}
141143
final topic = topics[index];
@@ -182,8 +184,8 @@ class _TopicsDataSource extends DataTableSource {
182184
onPressed: () {
183185
// Dispatch delete event
184186
context.read<ContentManagementBloc>().add(
185-
ArchiveTopicRequested(topic.id),
186-
);
187+
ArchiveTopicRequested(topic.id),
188+
);
187189
},
188190
),
189191
],
@@ -198,16 +200,6 @@ class _TopicsDataSource extends DataTableSource {
198200

199201
@override
200202
int get rowCount {
201-
// If we have more items to fetch, we add 1 to the current length.
202-
// This signals to PaginatedDataTable2 that there is at least one more page,
203-
// which enables the 'next page' button.
204-
if (hasMore) {
205-
// When loading, we show an extra row for the spinner.
206-
// Otherwise, we just indicate that there are more rows.
207-
return isLoading
208-
? topics.length + 1
209-
: topics.length + kDefaultRowsPerPage;
210-
}
211203
return topics.length;
212204
}
213205

0 commit comments

Comments
 (0)