mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
add loadNext
to search
This commit is contained in:
@@ -384,24 +384,18 @@ enum ExplorePageType {
|
|||||||
typedef SearchFunction = Future<Res<List<Comic>>> Function(
|
typedef SearchFunction = Future<Res<List<Comic>>> Function(
|
||||||
String keyword, int page, List<String> searchOption);
|
String keyword, int page, List<String> searchOption);
|
||||||
|
|
||||||
|
typedef SearchNextFunction = Future<Res<List<Comic>>> Function(
|
||||||
|
String keyword, String? next, List<String> searchOption);
|
||||||
|
|
||||||
class SearchPageData {
|
class SearchPageData {
|
||||||
/// If this is not null, the default value of search options will be first element.
|
/// If this is not null, the default value of search options will be first element.
|
||||||
final List<SearchOptions>? searchOptions;
|
final List<SearchOptions>? searchOptions;
|
||||||
|
|
||||||
final Widget Function(BuildContext, List<String> initialValues,
|
|
||||||
void Function(List<String>))? customOptionsBuilder;
|
|
||||||
|
|
||||||
final Widget Function(String keyword, List<String> options)?
|
|
||||||
overrideSearchResultBuilder;
|
|
||||||
|
|
||||||
final SearchFunction? loadPage;
|
final SearchFunction? loadPage;
|
||||||
|
|
||||||
final bool enableLanguageFilter;
|
final SearchNextFunction? loadNext;
|
||||||
|
|
||||||
const SearchPageData(this.searchOptions, this.loadPage)
|
const SearchPageData(this.searchOptions, this.loadPage, this.loadNext);
|
||||||
: enableLanguageFilter = false,
|
|
||||||
customOptionsBuilder = null,
|
|
||||||
overrideSearchResultBuilder = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SearchOptions {
|
class SearchOptions {
|
||||||
|
@@ -185,7 +185,7 @@ class ComicSourceParser {
|
|||||||
|
|
||||||
Future<Res<bool>> Function(String account, String pwd)? login;
|
Future<Res<bool>> Function(String account, String pwd)? login;
|
||||||
|
|
||||||
if(_checkExists("account.login")) {
|
if (_checkExists("account.login")) {
|
||||||
login = (account, pwd) async {
|
login = (account, pwd) async {
|
||||||
try {
|
try {
|
||||||
await JsEngine().runCode("""
|
await JsEngine().runCode("""
|
||||||
@@ -536,21 +536,47 @@ class ComicSourceParser {
|
|||||||
element['default'] == null ? null : jsonEncode(element['default']),
|
element['default'] == null ? null : jsonEncode(element['default']),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return SearchPageData(options, (keyword, page, searchOption) async {
|
|
||||||
try {
|
SearchFunction? loadPage;
|
||||||
var res = await JsEngine().runCode("""
|
|
||||||
|
SearchNextFunction? loadNext;
|
||||||
|
|
||||||
|
if (_checkExists('search.load')) {
|
||||||
|
loadPage = (keyword, page, searchOption) async {
|
||||||
|
try {
|
||||||
|
var res = await JsEngine().runCode("""
|
||||||
ComicSource.sources.$_key.search.load(
|
ComicSource.sources.$_key.search.load(
|
||||||
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(page)})
|
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(page)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
|
List.generate(res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
||||||
|
subData: res["maxPage"]);
|
||||||
|
} catch (e, s) {
|
||||||
|
Log.error("Network", "$e\n$s");
|
||||||
|
return Res.error(e.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
loadNext = (keyword, next, searchOption) async {
|
||||||
|
try {
|
||||||
|
var res = await JsEngine().runCode("""
|
||||||
|
ComicSource.sources.$_key.search.loadNext(
|
||||||
|
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(next)})
|
||||||
|
""");
|
||||||
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(res["comics"].length,
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
||||||
subData: res["maxPage"]);
|
subData: res["next"],
|
||||||
} catch (e, s) {
|
);
|
||||||
Log.error("Network", "$e\n$s");
|
} catch (e, s) {
|
||||||
return Res.error(e.toString());
|
Log.error("Network", "$e\n$s");
|
||||||
}
|
return Res.error(e.toString());
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return SearchPageData(options, loadPage, loadNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadComicFunc? _parseLoadComicFunc() {
|
LoadComicFunc? _parseLoadComicFunc() {
|
||||||
|
@@ -111,6 +111,7 @@ class _SearchResultPageState extends State<SearchResultPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var source = ComicSource.find(sourceKey);
|
||||||
return ComicList(
|
return ComicList(
|
||||||
key: Key(text + options.toString() + sourceKey),
|
key: Key(text + options.toString() + sourceKey),
|
||||||
errorLeading: AppSearchBar(
|
errorLeading: AppSearchBar(
|
||||||
@@ -122,9 +123,15 @@ class _SearchResultPageState extends State<SearchResultPage> {
|
|||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
action: buildAction(),
|
action: buildAction(),
|
||||||
),
|
),
|
||||||
loadPage: (i) {
|
loadPage: source!.searchPageData!.loadPage == null ? null : (i) {
|
||||||
var source = ComicSource.find(sourceKey);
|
return source.searchPageData!.loadPage!(
|
||||||
return source!.searchPageData!.loadPage!(
|
text,
|
||||||
|
i,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
loadNext: source.searchPageData!.loadNext == null ? null : (i) {
|
||||||
|
return source.searchPageData!.loadNext!(
|
||||||
text,
|
text,
|
||||||
i,
|
i,
|
||||||
options,
|
options,
|
||||||
|
Reference in New Issue
Block a user