feat(app): 剧场列表增加语种筛选
This commit is contained in:
1 parent
ade0cc3566
commit
30a5fa0776
5 files changed
+220
-4
No files matched your search
@@ -36,6 +36,7 @@ class DiscoverLogic extends ChangeNotifier {
|
||||
Duration searchDebounce = const Duration(milliseconds: 350);
|
||||
static const int searchPageSize = 20;
|
||||
List<Drama> searchResults = const [];
|
||||
String? selectedLanguage;
|
||||
int searchTotal = 0;
|
||||
bool searchLoading = false;
|
||||
String? searchError;
|
||||
@@ -87,8 +88,32 @@ class DiscoverLogic extends ChangeNotifier {
|
||||
|
||||
/// 搜索态展示后端结果,非搜索态展示剧场自身的可见短剧。
|
||||
List<Drama> visibleDramas(List<Drama> fallback) {
|
||||
if (!hasSearchQuery) return fallback;
|
||||
return searchResults;
|
||||
if (!hasSearchQuery) return _filterByLanguage(fallback);
|
||||
return _filterByLanguage(searchResults);
|
||||
}
|
||||
|
||||
/// 当前 feed 中出现过的语种,按首次出现顺序去重。
|
||||
List<String> languagesOf(List<Drama> dramas) {
|
||||
final languages = <String>[];
|
||||
for (final drama in dramas) {
|
||||
final language = drama.language;
|
||||
if (language.isNotEmpty && !languages.contains(language)) {
|
||||
languages.add(language);
|
||||
}
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
|
||||
/// 按语种筛选;null 表示全部。
|
||||
void selectLanguage(String? code) {
|
||||
selectedLanguage = code;
|
||||
notify();
|
||||
}
|
||||
|
||||
List<Drama> _filterByLanguage(List<Drama> dramas) {
|
||||
final code = selectedLanguage;
|
||||
if (code == null) return dramas;
|
||||
return dramas.where((drama) => drama.language == code).toList();
|
||||
}
|
||||
|
||||
Future<void> retrySearch() async {
|
||||
|
||||
Reference in new issue
Block a user