feat(app): 搜索改为调用后端并渲染卡片结果
This commit is contained in:
1 parent
730e38622f
commit
ade0cc3566
13 files changed
+424
-20
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/core/data/models/search_result.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/search_repository.dart';
|
||||
|
||||
/// 测试用目录数据:三部分区里的短剧,标题与后端演示数据保持一致。
|
||||
class FakeCatalogRepository implements CatalogRepository {
|
||||
class FakeCatalogRepository implements CatalogRepository, SearchRepository {
|
||||
FakeCatalogRepository({List<Drama>? dramas, this.banners = const []})
|
||||
: dramas = dramas ?? demoDramas;
|
||||
|
||||
@@ -21,6 +23,20 @@ class FakeCatalogRepository implements CatalogRepository {
|
||||
return dramas.firstWhere((drama) => drama.id == dramaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SearchResult> search(
|
||||
String keyword, {
|
||||
int pageIndex = 1,
|
||||
int pageSize = 20,
|
||||
}) async {
|
||||
final query = keyword.trim().toLowerCase();
|
||||
final hits = dramas.where((drama) {
|
||||
final haystack = [drama.title, drama.synopsis, drama.genre].join(' ');
|
||||
return haystack.toLowerCase().contains(query);
|
||||
}).toList();
|
||||
return SearchResult(total: hits.length, list: hits);
|
||||
}
|
||||
|
||||
HomeFeed _feed() => HomeFeed(
|
||||
banners: banners,
|
||||
sections: [FeedSection(code: 'hot', title: '热门推荐', dramas: dramas)],
|
||||
@@ -45,6 +61,7 @@ Drama _drama(String id, String title, String genre, {required int format}) =>
|
||||
synopsis: '$title synopsis',
|
||||
posterUrl: '/files/$id.png',
|
||||
genre: genre,
|
||||
language: 'id',
|
||||
detailLoaded: true,
|
||||
episodes: [
|
||||
for (var index = 0; index < 7; index++)
|
||||
|
||||
Reference in new issue
Block a user