Skip to content

Commit d72639e

Browse files
committed
refactor(content_management): improve sources page layout and functionality
- Remove conditional rendering of source type column - Replace custom filter map logic with bloc method - Update loading state icon to rss_feed - Adjust data table column sizing and content - Remove redundant isMobile parameter from data source
1 parent 9d17c72 commit d72639e

File tree

1 file changed

+30
-50
lines changed

1 file changed

+30
-50
lines changed

lib/content_management/view/sources_page.dart

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/content_management_bloc.dart';
66
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/sources_filter/sources_filter_bloc.dart';
7-
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/widgets/content_action_buttons.dart'; // Import the new widget
7+
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/widgets/content_action_buttons.dart';
88
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
99
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
1010
import 'package:flutter_news_app_web_dashboard_full_source_code/router/routes.dart';
11-
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/source_type_l10n.dart';
11+
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/extensions.dart';
1212
import 'package:go_router/go_router.dart';
1313
import 'package:intl/intl.dart';
1414
import 'package:ui_kit/ui_kit.dart';
@@ -32,40 +32,13 @@ class _SourcesPageState extends State<SourcesPage> {
3232
context.read<ContentManagementBloc>().add(
3333
LoadSourcesRequested(
3434
limit: kDefaultRowsPerPage,
35-
filter: _buildSourcesFilterMap(
36-
context.read<SourcesFilterBloc>().state,
37-
),
35+
filter: context
36+
.read<ContentManagementBloc>()
37+
.buildSourcesFilterMap(context.read<SourcesFilterBloc>().state),
3838
),
3939
);
4040
}
4141

42-
/// Builds a filter map for sources from the given filter state.
43-
Map<String, dynamic> _buildSourcesFilterMap(SourcesFilterState state) {
44-
final filter = <String, dynamic>{};
45-
46-
if (state.searchQuery.isNotEmpty) {
47-
filter['name'] = {r'$regex': state.searchQuery, r'$options': 'i'};
48-
}
49-
50-
filter['status'] = state.selectedStatus.name;
51-
52-
if (state.selectedSourceTypes.isNotEmpty) {
53-
filter['sourceType'] = {
54-
r'$in': state.selectedSourceTypes.map((s) => s.name).toList(),
55-
};
56-
}
57-
if (state.selectedLanguageCodes.isNotEmpty) {
58-
filter['language.code'] = {r'$in': state.selectedLanguageCodes};
59-
}
60-
if (state.selectedHeadquartersCountryIds.isNotEmpty) {
61-
filter['headquarters.id'] = {
62-
r'$in': state.selectedHeadquartersCountryIds,
63-
};
64-
}
65-
66-
return filter;
67-
}
68-
6942
@override
7043
Widget build(BuildContext context) {
7144
final l10n = AppLocalizationsX(context).l10n;
@@ -76,7 +49,7 @@ class _SourcesPageState extends State<SourcesPage> {
7649
if (state.sourcesStatus == ContentManagementStatus.loading &&
7750
state.sources.isEmpty) {
7851
return LoadingStateWidget(
79-
icon: Icons.source,
52+
icon: Icons.rss_feed,
8053
headline: l10n.loadingSources,
8154
subheadline: l10n.pleaseWait,
8255
);
@@ -89,9 +62,11 @@ class _SourcesPageState extends State<SourcesPage> {
8962
LoadSourcesRequested(
9063
limit: kDefaultRowsPerPage,
9164
forceRefresh: true,
92-
filter: _buildSourcesFilterMap(
93-
context.read<SourcesFilterBloc>().state,
94-
),
65+
filter: context
66+
.read<ContentManagementBloc>()
67+
.buildSourcesFilterMap(
68+
context.read<SourcesFilterBloc>().state,
69+
),
9570
),
9671
),
9772
);
@@ -116,11 +91,10 @@ class _SourcesPageState extends State<SourcesPage> {
11691
label: Text(l10n.sourceName),
11792
size: ColumnSize.L,
11893
),
119-
if (!isMobile) // Conditionally show Source Type
120-
DataColumn2(
121-
label: Text(l10n.sourceType),
122-
size: ColumnSize.S,
123-
),
94+
DataColumn2(
95+
label: Text(l10n.sourceType),
96+
size: ColumnSize.S,
97+
),
12498
DataColumn2(
12599
label: Text(l10n.lastUpdated),
126100
size: ColumnSize.S,
@@ -135,7 +109,7 @@ class _SourcesPageState extends State<SourcesPage> {
135109
sources: state.sources,
136110
hasMore: state.sourcesHasMore,
137111
l10n: l10n,
138-
isMobile: isMobile, // Pass isMobile to data source
112+
isMobile: isMobile,
139113
),
140114
rowsPerPage: kDefaultRowsPerPage,
141115
availableRowsPerPage: const [kDefaultRowsPerPage],
@@ -149,9 +123,11 @@ class _SourcesPageState extends State<SourcesPage> {
149123
LoadSourcesRequested(
150124
startAfterId: state.sourcesCursor,
151125
limit: kDefaultRowsPerPage,
152-
filter: _buildSourcesFilterMap(
153-
context.read<SourcesFilterBloc>().state,
154-
),
126+
filter: context
127+
.read<ContentManagementBloc>()
128+
.buildSourcesFilterMap(
129+
context.read<SourcesFilterBloc>().state,
130+
),
155131
),
156132
);
157133
}
@@ -182,14 +158,14 @@ class _SourcesDataSource extends DataTableSource {
182158
required this.sources,
183159
required this.hasMore,
184160
required this.l10n,
185-
required this.isMobile, // New parameter
161+
required this.isMobile,
186162
});
187163

188164
final BuildContext context;
189165
final List<Source> sources;
190166
final bool hasMore;
191167
final AppLocalizations l10n;
192-
final bool isMobile; // New parameter
168+
final bool isMobile;
193169

194170
@override
195171
DataRow? getRow(int index) {
@@ -214,11 +190,15 @@ class _SourcesDataSource extends DataTableSource {
214190
overflow: TextOverflow.ellipsis,
215191
),
216192
),
217-
if (!isMobile) // Conditionally show Source Type
218-
DataCell(Text(source.sourceType.localizedName(l10n))),
219193
DataCell(
220194
Text(
221-
// TODO(fulleni): Make date format configurable by admin.
195+
source.sourceType.localizedName(l10n),
196+
maxLines: 2,
197+
overflow: TextOverflow.ellipsis,
198+
),
199+
),
200+
DataCell(
201+
Text(
222202
DateFormat('dd-MM-yyyy').format(source.updatedAt.toLocal()),
223203
),
224204
),

0 commit comments

Comments
 (0)