mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
fix #14
This commit is contained in:
@@ -261,8 +261,14 @@ class LocalManager with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<LocalComic> getComics() {
|
||||
final res = _db.select('SELECT * FROM comics;');
|
||||
List<LocalComic> getComics(LocalSortType sortType) {
|
||||
var res = _db.select('''
|
||||
SELECT * FROM comics
|
||||
ORDER BY
|
||||
${sortType.value == 'name' ? 'title' : 'created_at'}
|
||||
${sortType.value == 'time_asc' ? 'ASC' : 'DESC'}
|
||||
;
|
||||
''');
|
||||
return res.map((row) => LocalComic.fromRow(row)).toList();
|
||||
}
|
||||
|
||||
@@ -310,6 +316,15 @@ class LocalManager with ChangeNotifier {
|
||||
return LocalComic.fromRow(res.first);
|
||||
}
|
||||
|
||||
List<LocalComic> search(String keyword) {
|
||||
final res = _db.select('''
|
||||
SELECT * FROM comics
|
||||
WHERE title LIKE ? OR tags LIKE ? OR subtitle LIKE ?
|
||||
ORDER BY created_at DESC;
|
||||
''', ['%$keyword%', '%$keyword%', '%$keyword%']);
|
||||
return res.map((row) => LocalComic.fromRow(row)).toList();
|
||||
}
|
||||
|
||||
Future<List<String>> getImages(String id, ComicType type, Object ep) async {
|
||||
if(ep is! String && ep is! int) {
|
||||
throw "Invalid ep";
|
||||
@@ -429,3 +444,22 @@ class LocalManager with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
enum LocalSortType {
|
||||
name("name"),
|
||||
timeAsc("time_asc"),
|
||||
timeDesc("time_desc");
|
||||
|
||||
final String value;
|
||||
|
||||
const LocalSortType(this.value);
|
||||
|
||||
static LocalSortType fromString(String value) {
|
||||
for (var type in values) {
|
||||
if (type.value == value) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user