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