Skip to content

Commit

Permalink
✨ search comics
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Nov 11, 2023
1 parent 368c97c commit 5f0b696
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/ffi.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:ffi';
import 'dart:io';
import 'bridge_generated.dart';

const base = 'rust';
const base = 'native';
// final path = Platform.isWindows ? '$base.dll' : Platform.isMacOS ? "lib$base.dylib" : 'lib$base.so';
// late final dylib = loadLibForFlutter(path);
final dylib = Platform.isWindows
Expand Down
71 changes: 71 additions & 0 deletions lib/screens/comic_search_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:flutter_search_bar/flutter_search_bar.dart' as sb;

import '../ffi.io.dart';
import 'components/comic_list.dart';
import 'components/comic_pager.dart';

class ComicSearchScreen extends StatefulWidget {
final String initialQuery;

const ComicSearchScreen({super.key, required this.initialQuery});

@override
_ComicSearchScreenState createState() => _ComicSearchScreenState();
}

class _ComicSearchScreenState extends State<ComicSearchScreen> {
late var _query = widget.initialQuery;

late final _searchBar = sb.SearchBar(
hintText: '搜索',
inBar: false,
setState: setState,
onSubmitted: (value) {
if (value.isNotEmpty) {
setState(() {
_query = value;
});
}
},
buildDefaultAppBar: _appBar,
);

AppBar _appBar(BuildContext context) {
return AppBar(
title: Text(_query),
actions: [
_searchBar.getSearchAction(context),
],
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
key: Key("search_screen:$_query"),
appBar: _searchBar.build(context),
body: ComicPager(fetcher: (offset, limit) async {
final result = await api.comicSearch(
qType: "", q: _query, offset: offset, limit: limit);
return CommonPage<CommonComicInfo>(
list: result.list
.map((e) => CommonComicInfo(
author: e.author,
cover: e.cover,
imgType: e.imgType,
name: e.name,
pathWord: e.pathWord,
popular: e.popular,
males: e.males,
females: e.females,
))
.toList(),
total: result.total,
limit: result.limit,
offset: result.offset,
);
}),
);
}
}
13 changes: 7 additions & 6 deletions lib/screens/discovery_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:kobi/bridge_generated.dart';
import 'package:kobi/screens/comic_search_screen.dart';
import 'package:kobi/screens/components/content_error.dart';
import 'package:flutter_search_bar/flutter_search_bar.dart' as sb;
import '../ffi.io.dart';
Expand Down Expand Up @@ -43,12 +44,12 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
setState: setState,
onSubmitted: (value) {
if (value.isNotEmpty) {
// Navigator.push(
// context,
// mixRoute(
// builder: (context) => SearchScreen(keyword: value),
// ),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ComicSearchScreen(initialQuery: value),
),
);
}
},
buildDefaultAppBar: _buildNormalAppBar,
Expand Down
2 changes: 1 addition & 1 deletion native/src/copy_client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ impl Client {
&self,
q_type: &str,
q: &str,
limit: u64,
offset: u64,
limit: u64,
) -> Result<Page<ComicInSearch>> {
self.request(
reqwest::Method::GET,
Expand Down
1 change: 1 addition & 0 deletions native/src/copy_client/dtos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct Comic {
pub author: Vec<Author>,
pub b_404: bool,
pub b_hidden: bool,
#[serde(default)]
pub ban: i64,
pub brief: String,
pub close_comment: bool,
Expand Down
7 changes: 7 additions & 0 deletions native/src/copy_client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ async fn test_request() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn test_comic() -> Result<()> {
let value = client().comic("dokunidakareteoboreteitai").await?;
println!("{}", serde_json::to_string(&value).unwrap());
Ok(())
}

#[tokio::test]
async fn test_chapters() -> Result<()> {
let value = client()
Expand Down

0 comments on commit 5f0b696

Please sign in to comment.