Skip to content

Commit

Permalink
fix: search filter reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
snaoyam committed Jul 31, 2023
1 parent 148f48c commit b2defbb
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 40 deletions.
5 changes: 4 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cancel": "Cancel",
"delete": "Delete",
"reset": "Reset",
"reset_all": "Reset All",
"search": "Search",
"upload": "Upload",
"edit": "Edit",
Expand All @@ -13,7 +14,9 @@
"no_result": "No result.",
"select_all": "Select All",
"unselect_all": "Unselect All",
"no_info": "No information"
"no_info": "No information",
"all_selected": "All Selected",
"num_selected": " Selected"
},
"semester": {
"spring": "Spring",
Expand Down
5 changes: 4 additions & 1 deletion assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cancel": "취소",
"delete": "삭제",
"reset": "초기화",
"reset_all": "전체 초기화",
"search": "검색",
"upload": "업로드",
"edit": "수정",
Expand All @@ -13,7 +14,9 @@
"no_result": "검색 결과가 없습니다.",
"select_all": "모두 선택",
"unselect_all": "모두 해제",
"no_info": "정보 없음"
"no_info": "정보 없음",
"all_selected": "전체 선택됨",
"num_selected": "개 선택됨"
},
"semester": {
"spring": "",
Expand Down
2 changes: 1 addition & 1 deletion lib/models/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class CodeLabelPair {
final String code;
final String label;
bool selected;
CodeLabelPair({required this.code, this.label = "", this.selected = true});
CodeLabelPair({required this.code, this.label = "", this.selected = false});
}
2 changes: 1 addition & 1 deletion lib/pages/course_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _CourseSearchPageState extends State<CourseSearchPage> {
_focusNode.requestFocus();
},
child: Text(
"common.reset".tr(),
"common.reset_all".tr(),
style: bodyBold.copyWith(color: OTLColor.pinksMain),
),
style: ButtonStyle(
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/lecture_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _LectureSearchPageState extends State<LectureSearchPage> {
_focusNode.requestFocus();
},
child: Text(
"common.reset".tr(),
"common.reset_all".tr(),
style: bodyBold.copyWith(color: OTLColor.pinksMain),
),
style: ButtonStyle(
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/course_search_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CourseSearchModel extends ChangeNotifier {
_courseSearchText = '';
_courseFilter.values.forEach((e) {
if (e.isMultiSelect)
e.options.forEach((b) => b.forEach((c) => c.selected = true));
e.options.forEach((b) => b.forEach((c) => c.selected = false));
else {
e.options.forEach((b) => b.forEach((c) => c.selected = false));
e.options.first.first.selected = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/lecture_search_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class LectureSearchModel extends ChangeNotifier {
_lectureSearchText = '';
_lectureFilter.values.forEach((e) {
if (e.isMultiSelect)
e.options.forEach((b) => b.forEach((c) => c.selected = true));
e.options.forEach((b) => b.forEach((c) => c.selected = false));
else {
e.options.forEach((b) => b.forEach((c) => c.selected = false));
e.options.first.first.selected = true;
Expand Down
77 changes: 44 additions & 33 deletions lib/widgets/search_filter_panel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:easy_localization/easy_localization.dart' as _;
import 'package:flutter/material.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/constants/text_styles.dart';
Expand Down Expand Up @@ -92,44 +93,54 @@ class _SelectorState extends State<Selector> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.title,
style: titleBold,
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
widget.title,
style: titleBold,
),
SizedBox(width: 8),
Visibility(
visible: widget.isMultiSelect,
child: Text.rich(TextSpan(
children: widget.selectList
.expand((i) => i)
.where((i) => i.selected == true)
.length ==
0
? [TextSpan(text: "common.all_selected".tr())]
: [
TextSpan(
text: widget.selectList
.expand((i) => i)
.where((i) => i.selected == true)
.length
.toString()),
TextSpan(text: "common.num_selected".tr()),
],
style: bodyRegular,
)),
)
],
),
Visibility(
visible: widget.isMultiSelect,
child: GestureDetector(
visible: widget.isMultiSelect &&
!widget.selectList.every(
(v) => v.every((w) => w.selected == false),
),
child: IconTextButton(
onTap: () {
if (widget.selectList
.every((v) => v.every((w) => w.selected == true))) {
widget.selectList.forEach((v) {
v.forEach((w) {
widget.setFilter(w.code, false);
});
});
} else {
widget.selectList.forEach((v) {
v.forEach((w) {
widget.setFilter(w.code, true);
});
widget.selectList.forEach((v) {
v.forEach((w) {
widget.setFilter(w.code, false);
});
}
});
},
child: Text.rich(
TextSpan(
style: bodyRegular.copyWith(
color: OTLColor.pinksMain,
decoration: TextDecoration.underline,
),
text: widget.selectList.every(
(v) => v.every((w) => w.selected == true),
)
// unknown error
// ? "common.unselect_all".tr()
// : "common.select_all".tr()
? "모두 해제"
: "모두 선택",
),
text: "common.reset".tr(),
textStyle: bodyRegular.copyWith(
color: OTLColor.pinksMain,
decoration: TextDecoration.underline,
),
),
)
Expand Down

0 comments on commit b2defbb

Please sign in to comment.