diff --git a/lib/src/controllers/release_event_search_controller.dart b/lib/src/controllers/release_event_search_controller.dart index a28b84bf..9a7f59b3 100644 --- a/lib/src/controllers/release_event_search_controller.dart +++ b/lib/src/controllers/release_event_search_controller.dart @@ -1,24 +1,13 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:vocadb_app/controllers.dart'; import 'package:vocadb_app/models.dart'; import 'package:vocadb_app/repositories.dart'; import 'package:vocadb_app/services.dart'; import 'package:vocadb_app/utils.dart'; -class ReleaseEventSearchController extends GetxController { - final int maxResults = 50; - - final initialLoading = true.obs; - - /// List of results from search - final results = [].obs; - - /// Query input string - final query = ''.obs; - - /// Set to True when user tap search icon. - final openQuery = false.obs; - +class ReleaseEventSearchController + extends SearchPageController { /// Filter parameter final category = ''.obs; @@ -32,9 +21,6 @@ class ReleaseEventSearchController extends GetxController { final tags = [].obs; - /// If set to [True], no fetch more data from server. Default is [False]. - final noFetchMore = false.obs; - final ReleaseEventRepository releaseEventRepository; TextEditingController textSearchController; @@ -43,22 +29,11 @@ class ReleaseEventSearchController extends GetxController { @override void onInit() { - initialFetch(); [category, sort, artists, tags, fromDate, toDate] .forEach((element) => ever(element, (_) => initialFetch())); - debounce(query, (_) => initialFetch(), time: Duration(seconds: 1)); - textSearchController = TextEditingController(); super.onInit(); } - void initialFetch() { - Future.value(noFetchMore(false)) - .then((_) => fetchApi()) - .then(verifyShouldFetchMore) - .then(results) - .then(initialLoadingDone); - } - Future> fetchApi({int start}) => releaseEventRepository.findReleaseEvents( start: (start == null) ? 0 : start, @@ -72,24 +47,4 @@ class ReleaseEventSearchController extends GetxController { beforeDate: DateTimeUtils.toUtcDateString(toDate.value), afterDate: DateTimeUtils.toUtcDateString(fromDate.value), ); - - clearQuery() { - query(''); - textSearchController.clear(); - } - - initialLoadingDone(_) => initialLoading(false); - - List verifyShouldFetchMore(List items) { - if (items == null || items.isEmpty || items.length < maxResults) - noFetchMore(true); - return items; - } - - onReachLastItem() { - if (noFetchMore.value) return; - fetchApi(start: results.length + 1) - .then(verifyShouldFetchMore) - .then(results.addAll); - } } diff --git a/lib/src/pages/release_event_search_page.dart b/lib/src/pages/release_event_search_page.dart index 79e0f9e9..be296105 100644 --- a/lib/src/pages/release_event_search_page.dart +++ b/lib/src/pages/release_event_search_page.dart @@ -59,11 +59,13 @@ class ReleaseEventSearchPage extends GetView { body: Obx( () => (controller.initialLoading.value) ? CenterLoading() - : ReleaseEventListView( - events: controller.results.toList(), - onSelect: this._onTapReleaseEvent, - onReachLastItem: controller.onReachLastItem, - ), + : (controller.errorMessage.string.isNotEmpty) + ? CenterText(controller.errorMessage.string) + : ReleaseEventListView( + events: controller.results.toList(), + onSelect: this._onTapReleaseEvent, + onReachLastItem: controller.onReachLastItem, + emptyWidget: CenterText('searchResultNotMatched'.tr)), )); } } diff --git a/lib/src/widgets/release_event_list_view.dart b/lib/src/widgets/release_event_list_view.dart index 4797fc9b..e0f5c8fa 100644 --- a/lib/src/widgets/release_event_list_view.dart +++ b/lib/src/widgets/release_event_list_view.dart @@ -4,7 +4,11 @@ import 'package:vocadb_app/widgets.dart'; class ReleaseEventListView extends StatelessWidget { ReleaseEventListView( - {Key key, this.events, this.onSelect, this.onReachLastItem}) + {Key key, + this.events, + this.onSelect, + this.onReachLastItem, + this.emptyWidget}) : super(key: key); /// List of events to display. @@ -15,8 +19,15 @@ class ReleaseEventListView extends StatelessWidget { /// A callback function when user react to last item. Only worked on list view with vertical direction. final Function onReachLastItem; + /// A widget that display when songs is empty + final Widget emptyWidget; + @override Widget build(BuildContext context) { + if (events.isEmpty && this.emptyWidget != null) { + return this.emptyWidget; + } + return InfiniteListView( onReachLastItem: this.onReachLastItem, itemCount: this.events.length,