Skip to content

Commit 538bf4b

Browse files
authored
Merge pull request #143 from flutter-news-app-full-source-code/refactor/engagement-table-and-filter-enhancement
Refactor/engagement table and filter enhancement
2 parents 41c74e3 + 8e75783 commit 538bf4b

File tree

8 files changed

+77
-24
lines changed

8 files changed

+77
-24
lines changed

lib/community_management/bloc/community_management_bloc.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,27 @@ class CommunityManagementBloc
104104
}
105105

106106
Map<String, dynamic> buildEngagementsFilterMap(EngagementsFilter filter) {
107-
final filterMap = <String, dynamic>{};
107+
final conditions = <Map<String, dynamic>>[];
108+
108109
if (filter.searchQuery != null && filter.searchQuery!.isNotEmpty) {
109-
filterMap['userId'] = filter.searchQuery;
110+
conditions.add({'userId': filter.searchQuery});
110111
}
112+
111113
if (filter.selectedStatus != null) {
112-
filterMap['comment.status'] = {
113-
r'$in': [filter.selectedStatus!.name],
114-
};
114+
if (filter.selectedStatus == ModerationStatus.resolved) {
115+
conditions.add({'comment.status': ModerationStatus.resolved.name});
116+
} else {
117+
conditions.add({'comment.status': filter.selectedStatus!.name});
118+
}
119+
}
120+
121+
if (conditions.isEmpty) {
122+
return {};
123+
} else if (conditions.length == 1) {
124+
return conditions.first;
125+
} else {
126+
return {r'$and': conditions};
115127
}
116-
return filterMap;
117128
}
118129

119130
Map<String, dynamic> buildReportsFilterMap(ReportsFilter filter) {

lib/community_management/view/engagements_page.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ class _EngagementsDataSource extends DataTableSource {
210210
side: BorderSide.none,
211211
visualDensity: VisualDensity.compact,
212212
)
213-
: Text(
214-
l10n.notAvailable,
215-
style: Theme.of(context).textTheme.bodySmall?.copyWith(
216-
color: Theme.of(
217-
context,
218-
).colorScheme.onSurface.withOpacity(0.6),
219-
),
213+
: Chip(
214+
label: Text(l10n.notAvailable),
215+
backgroundColor: Theme.of(
216+
context,
217+
).colorScheme.onSurface.withOpacity(0.1),
218+
side: BorderSide.none,
219+
visualDensity: VisualDensity.compact,
220220
),
221221
),
222222
DataCell(

lib/community_management/widgets/community_filter_dialog/community_filter_dialog.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,19 @@ class _CommunityFilterDialogState extends State<CommunityFilterDialog> {
248248
case CommunityManagementTab.engagements:
249249
return [
250250
_buildCapsuleFilter<ModerationStatus>(
251-
title: l10n.status,
251+
title: l10n.commentStatus,
252252
allValues: ModerationStatus.values,
253253
selectedValue: state.engagementsFilter.selectedStatus,
254254
labelBuilder: (item) => item.l10n(context),
255255
onChanged: (item) {
256256
context.read<CommunityFilterBloc>().add(
257-
EngagementsFilterChanged(
258-
EngagementsFilter(
259-
searchQuery: state.engagementsFilter.searchQuery,
260-
selectedStatus: item,
261-
),
262-
),
263-
);
257+
EngagementsFilterChanged(
258+
EngagementsFilter(
259+
searchQuery: state.engagementsFilter.searchQuery,
260+
selectedStatus: item,
261+
),
262+
),
263+
);
264264
},
265265
),
266266
];

lib/l10n/app_localizations.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3440,12 +3440,24 @@ abstract class AppLocalizations {
34403440
/// **'Comment'**
34413441
String get comment;
34423442

3443-
/// Column header for comment status
3443+
/// Label for the moderation status of a comment within an engagement.
34443444
///
34453445
/// In en, this message translates to:
34463446
/// **'Comment Status'**
34473447
String get commentStatus;
34483448

3449+
/// Label for the switch to filter engagements based on whether they have a comment.
3450+
///
3451+
/// In en, this message translates to:
3452+
/// **'Contains Comment'**
3453+
String get hasCommentFilterLabel;
3454+
3455+
/// Description for the switch to filter engagements based on whether they have a comment.
3456+
///
3457+
/// In en, this message translates to:
3458+
/// **'Show only engagements that include a text comment.'**
3459+
String get hasCommentFilterDescription;
3460+
34493461
/// Column header for date
34503462
///
34513463
/// In en, this message translates to:

lib/l10n/app_localizations_ar.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,13 @@ class AppLocalizationsAr extends AppLocalizations {
18581858
@override
18591859
String get commentStatus => 'حالة التعليق';
18601860

1861+
@override
1862+
String get hasCommentFilterLabel => 'تحتوي على تعليقات';
1863+
1864+
@override
1865+
String get hasCommentFilterDescription =>
1866+
'إظهار التفاعلات التي تتضمن تعليقًا نصيًا فقط.';
1867+
18611868
@override
18621869
String get date => 'التاريخ';
18631870

lib/l10n/app_localizations_en.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,13 @@ class AppLocalizationsEn extends AppLocalizations {
18631863
@override
18641864
String get commentStatus => 'Comment Status';
18651865

1866+
@override
1867+
String get hasCommentFilterLabel => 'Contains Comment';
1868+
1869+
@override
1870+
String get hasCommentFilterDescription =>
1871+
'Show only engagements that include a text comment.';
1872+
18661873
@override
18671874
String get date => 'Date';
18681875

lib/l10n/arb/app_ar.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,15 @@
23162316
},
23172317
"commentStatus": "حالة التعليق",
23182318
"@commentStatus": {
2319-
"description": "رأس العمود لحالة التعليق"
2319+
"description": "تسمية لحالة الإشراف على تعليق ضمن تفاعل."
2320+
},
2321+
"hasCommentFilterLabel": "تحتوي على تعليقات",
2322+
"@hasCommentFilterLabel": {
2323+
"description": "تسمية لمفتاح تصفية التفاعلات بناءً على وجود تعليق."
2324+
},
2325+
"hasCommentFilterDescription": "إظهار التفاعلات التي تتضمن تعليقًا نصيًا فقط.",
2326+
"@hasCommentFilterDescription": {
2327+
"description": "وصف لمفتاح تصفية التفاعلات بناءً على وجود تعليق."
23202328
},
23212329
"date": "التاريخ",
23222330
"@date": {

lib/l10n/arb/app_en.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,15 @@
23122312
},
23132313
"commentStatus": "Comment Status",
23142314
"@commentStatus": {
2315-
"description": "Column header for comment status"
2315+
"description": "Label for the moderation status of a comment within an engagement."
2316+
},
2317+
"hasCommentFilterLabel": "Contains Comment",
2318+
"@hasCommentFilterLabel": {
2319+
"description": "Label for the switch to filter engagements based on whether they have a comment."
2320+
},
2321+
"hasCommentFilterDescription": "Show only engagements that include a text comment.",
2322+
"@hasCommentFilterDescription": {
2323+
"description": "Description for the switch to filter engagements based on whether they have a comment."
23162324
},
23172325
"date": "Date",
23182326
"@date": {

0 commit comments

Comments
 (0)