mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-07-05 08:51:36 +00:00
search for books
This commit is contained in:
parent
a1e238fc25
commit
d372a6b096
12 changed files with 963 additions and 88 deletions
85
lib/features/explore/view/search_result_page.dart
Normal file
85
lib/features/explore/view/search_result_page.dart
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
import 'package:whispering_pages/features/explore/providers/search_result_provider.dart';
|
||||
import 'package:whispering_pages/features/explore/view/explore_page.dart';
|
||||
|
||||
enum SearchResultCategory {
|
||||
books,
|
||||
authors,
|
||||
series,
|
||||
tags,
|
||||
narrators,
|
||||
}
|
||||
|
||||
class SearchResultPage extends HookConsumerWidget {
|
||||
const SearchResultPage({
|
||||
super.key,
|
||||
required this.query,
|
||||
this.category,
|
||||
Object? extra,
|
||||
});
|
||||
|
||||
/// The search query.
|
||||
final String query;
|
||||
|
||||
/// The category of the search result, if not provided, the search result will be displayed in all categories.
|
||||
final SearchResultCategory? category;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final results = ref.watch(searchResultProvider(query));
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
category != null
|
||||
? '${category.toString().split('.').last} in "$query"'
|
||||
: 'Search result for $query',
|
||||
),
|
||||
),
|
||||
body: results.when(
|
||||
data: (options) {
|
||||
if (options == null) {
|
||||
return Container(
|
||||
child: const Text('No data found'),
|
||||
);
|
||||
}
|
||||
if (options is BookLibrarySearchResponse) {
|
||||
if (category == null) {
|
||||
return Container();
|
||||
}
|
||||
return switch (category!) {
|
||||
SearchResultCategory.books => ListView.builder(
|
||||
itemCount: options.book.length,
|
||||
itemBuilder: (context, index) {
|
||||
final book = BookExpanded.fromJson(
|
||||
options.book[index].libraryItem.media.toJson(),
|
||||
);
|
||||
final metadata = BookMetadataExpanded.fromJson(
|
||||
book.metadata.toJson(),
|
||||
);
|
||||
|
||||
return BookSearchResultMini(
|
||||
book: book,
|
||||
metadata: metadata,
|
||||
);
|
||||
},
|
||||
),
|
||||
SearchResultCategory.authors => Container(),
|
||||
SearchResultCategory.series => Container(),
|
||||
SearchResultCategory.tags => Container(),
|
||||
SearchResultCategory.narrators => Container(),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
error: (error, stackTrace) => Center(
|
||||
child: Text('Error: $error'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue