Skip to content

Commit c800880

Browse files
committed
refactor(content_management): improve sources table loading state
- Remove loading row from _SourcesDataSource - Add LinearProgressIndicator to _SourcesPageState - Adjust row count logic in _SourcesDataSource - Remove isLoading parameter from _SourcesDataSource constructor
1 parent 2fcfb21 commit c800880

File tree

1 file changed

+60
-63
lines changed

1 file changed

+60
-63
lines changed

lib/content_management/view/sources_page.dart

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,66 @@ class _SourcesPageState extends State<SourcesPage> {
6161
return Center(child: Text(l10n.noSourcesFound));
6262
}
6363

64-
return PaginatedDataTable2(
65-
columns: [
66-
DataColumn2(label: Text(l10n.sourceName), size: ColumnSize.L),
67-
DataColumn2(label: Text(l10n.sourceType), size: ColumnSize.M),
68-
DataColumn2(label: Text(l10n.status), size: ColumnSize.S),
69-
DataColumn2(label: Text(l10n.lastUpdated), size: ColumnSize.M),
70-
DataColumn2(
71-
label: Text(l10n.actions),
72-
size: ColumnSize.S,
73-
fixedWidth: 120,
64+
return Column(
65+
children: [
66+
if (state.sourcesStatus == ContentManagementStatus.loading &&
67+
state.sources.isNotEmpty)
68+
const LinearProgressIndicator(),
69+
Expanded(
70+
child: PaginatedDataTable2(
71+
columns: [
72+
DataColumn2(
73+
label: Text(l10n.sourceName),
74+
size: ColumnSize.L,
75+
),
76+
DataColumn2(
77+
label: Text(l10n.sourceType),
78+
size: ColumnSize.M,
79+
),
80+
DataColumn2(label: Text(l10n.status), size: ColumnSize.S),
81+
DataColumn2(
82+
label: Text(l10n.lastUpdated),
83+
size: ColumnSize.M,
84+
),
85+
DataColumn2(
86+
label: Text(l10n.actions),
87+
size: ColumnSize.S,
88+
fixedWidth: 120,
89+
),
90+
],
91+
source: _SourcesDataSource(
92+
context: context,
93+
sources: state.sources,
94+
hasMore: state.sourcesHasMore,
95+
l10n: l10n,
96+
),
97+
rowsPerPage: kDefaultRowsPerPage,
98+
availableRowsPerPage: const [kDefaultRowsPerPage],
99+
onPageChanged: (pageIndex) {
100+
final newOffset = pageIndex * kDefaultRowsPerPage;
101+
if (newOffset >= state.sources.length &&
102+
state.sourcesHasMore &&
103+
state.sourcesStatus !=
104+
ContentManagementStatus.loading) {
105+
context.read<ContentManagementBloc>().add(
106+
LoadSourcesRequested(
107+
startAfterId: state.sourcesCursor,
108+
limit: kDefaultRowsPerPage,
109+
),
110+
);
111+
}
112+
},
113+
empty: Center(child: Text(l10n.noSourcesFound)),
114+
showCheckboxColumn: false,
115+
showFirstLastButtons: true,
116+
fit: FlexFit.tight,
117+
headingRowHeight: 56,
118+
dataRowHeight: 56,
119+
columnSpacing: AppSpacing.md,
120+
horizontalMargin: AppSpacing.md,
121+
),
74122
),
75123
],
76-
source: _SourcesDataSource(
77-
context: context,
78-
sources: state.sources,
79-
isLoading: state.sourcesStatus == ContentManagementStatus.loading,
80-
hasMore: state.sourcesHasMore,
81-
l10n: l10n,
82-
),
83-
rowsPerPage: kDefaultRowsPerPage,
84-
availableRowsPerPage: const [kDefaultRowsPerPage],
85-
onPageChanged: (pageIndex) {
86-
final newOffset = pageIndex * kDefaultRowsPerPage;
87-
if (newOffset >= state.sources.length &&
88-
state.sourcesHasMore &&
89-
state.sourcesStatus != ContentManagementStatus.loading) {
90-
context.read<ContentManagementBloc>().add(
91-
LoadSourcesRequested(
92-
startAfterId: state.sourcesCursor,
93-
limit: kDefaultRowsPerPage,
94-
),
95-
);
96-
}
97-
},
98-
empty: Center(child: Text(l10n.noSourcesFound)),
99-
showCheckboxColumn: false,
100-
showFirstLastButtons: true,
101-
fit: FlexFit.tight,
102-
headingRowHeight: 56,
103-
dataRowHeight: 56,
104-
columnSpacing: AppSpacing.md,
105-
horizontalMargin: AppSpacing.md,
106124
);
107125
},
108126
),
@@ -114,29 +132,18 @@ class _SourcesDataSource extends DataTableSource {
114132
_SourcesDataSource({
115133
required this.context,
116134
required this.sources,
117-
required this.isLoading,
118135
required this.hasMore,
119136
required this.l10n,
120137
});
121138

122139
final BuildContext context;
123140
final List<Source> sources;
124-
final bool isLoading;
125141
final bool hasMore;
126142
final AppLocalizations l10n;
127143

128144
@override
129145
DataRow? getRow(int index) {
130146
if (index >= sources.length) {
131-
// This can happen if hasMore is true and the user is on the last page.
132-
// If we are loading, show a spinner. Otherwise, we've reached the end.
133-
if (isLoading) {
134-
return DataRow2(
135-
cells: List.generate(5, (_) {
136-
return const DataCell(Center(child: CircularProgressIndicator()));
137-
}),
138-
);
139-
}
140147
return null;
141148
}
142149
final source = sources[index];
@@ -184,8 +191,8 @@ class _SourcesDataSource extends DataTableSource {
184191
onPressed: () {
185192
// Dispatch delete event
186193
context.read<ContentManagementBloc>().add(
187-
ArchiveSourceRequested(source.id),
188-
);
194+
ArchiveSourceRequested(source.id),
195+
);
189196
},
190197
),
191198
],
@@ -200,16 +207,6 @@ class _SourcesDataSource extends DataTableSource {
200207

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

0 commit comments

Comments
 (0)