mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve aggregated_search_page
This commit is contained in:
@@ -417,7 +417,7 @@ class SearchOptions {
|
|||||||
|
|
||||||
const SearchOptions(this.options, this.label, this.type, this.defaultVal);
|
const SearchOptions(this.options, this.label, this.type, this.defaultVal);
|
||||||
|
|
||||||
String get defaultValue => defaultVal ?? options.keys.first;
|
String get defaultValue => defaultVal ?? options.keys.firstOrNull ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef CategoryComicsLoader = Future<Res<List<Comic>>> Function(
|
typedef CategoryComicsLoader = Future<Res<List<Comic>>> Function(
|
||||||
|
@@ -58,7 +58,11 @@ class _AggregatedSearchPageState extends State<AggregatedSearchPage> {
|
|||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, index) {
|
(context, index) {
|
||||||
final source = sources[index];
|
final source = sources[index];
|
||||||
return _SliverSearchResult(source: source, keyword: _keyword);
|
return _SliverSearchResult(
|
||||||
|
key: ValueKey(source.key),
|
||||||
|
source: source,
|
||||||
|
keyword: _keyword,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
childCount: sources.length,
|
childCount: sources.length,
|
||||||
),
|
),
|
||||||
@@ -68,7 +72,11 @@ class _AggregatedSearchPageState extends State<AggregatedSearchPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SliverSearchResult extends StatefulWidget {
|
class _SliverSearchResult extends StatefulWidget {
|
||||||
const _SliverSearchResult({required this.source, required this.keyword});
|
const _SliverSearchResult({
|
||||||
|
required this.source,
|
||||||
|
required this.keyword,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final ComicSource source;
|
final ComicSource source;
|
||||||
|
|
||||||
@@ -90,6 +98,8 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
|
|
||||||
List<Comic>? comics;
|
List<Comic>? comics;
|
||||||
|
|
||||||
|
String? error;
|
||||||
|
|
||||||
void load() async {
|
void load() async {
|
||||||
final data = widget.source.searchPageData!;
|
final data = widget.source.searchPageData!;
|
||||||
var options =
|
var options =
|
||||||
@@ -101,6 +111,11 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
comics = res.data;
|
comics = res.data;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
error = res.errorMessage ?? "Unknown error".tl;
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (data.loadNext != null) {
|
} else if (data.loadNext != null) {
|
||||||
var res = await data.loadNext!(widget.keyword, null, options);
|
var res = await data.loadNext!(widget.keyword, null, options);
|
||||||
@@ -109,6 +124,11 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
comics = res.data;
|
comics = res.data;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
error = res.errorMessage ?? "Unknown error".tl;
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,6 +159,9 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (error != null && error!.startsWith("CloudflareException")) {
|
||||||
|
error = "Cloudflare verification required".tl;
|
||||||
|
}
|
||||||
super.build(context);
|
super.build(context);
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@@ -181,7 +204,7 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else if (comics == null || comics!.isEmpty)
|
else if (error != null || comics == null || comics!.isEmpty)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: _kComicHeight,
|
height: _kComicHeight,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -190,7 +213,13 @@ class _SliverSearchResultState extends State<_SliverSearchResult>
|
|||||||
children: [
|
children: [
|
||||||
const Icon(Icons.error_outline),
|
const Icon(Icons.error_outline),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text("No search results found".tl),
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
error ?? "No search results found".tl,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
Reference in New Issue
Block a user