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 524fa07 commit ade4b64
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 29 deletions.
5 changes: 4 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"delete": "Delete",
"add": "Add",
"reset": "Reset",
"reset_all": "Reset All",
"search": "Search",
"upload": "Upload",
"edit": "Edit",
Expand All @@ -14,7 +15,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 @@ -6,6 +6,7 @@
"delete": "삭제",
"add": "추가하기",
"reset": "초기화",
"reset_all": "전체 초기화",
"search": "검색",
"upload": "업로드",
"edit": "수정",
Expand All @@ -14,7 +15,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 @@ -109,7 +109,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 @@ -109,7 +109,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
61 changes: 39 additions & 22 deletions lib/widgets/search_filter_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,51 @@ 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,
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);
});
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);
});
});
}
});
},
text: widget.selectList.every(
(v) => v.every((w) => w.selected == true),
)
? "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 ade4b64

Please sign in to comment.