feat: 添加画廊列表显示模式和合并功能,优化画廊列表卡片组件

This commit is contained in:
2025-03-08 17:11:16 +08:00
parent 5f92d036fa
commit e64910d572
9 changed files with 183 additions and 6 deletions

View File

@@ -27,6 +27,14 @@ class ApiResult<T> {
}
}
T? unwrapOrNull() {
if (ok) {
return data;
} else {
return null;
}
}
(int, String) unwrapErr() {
if (ok) {
return throw 'unwrap_err called on ok ApiResult';

View File

@@ -41,8 +41,8 @@ class EhFileExtend {
}
class EhFiles {
const EhFiles({required this.files});
final Map<String, List<EhFileBasic>> files;
EhFiles({required this.files});
Map<String, List<EhFileBasic>> files;
factory EhFiles.fromJson(Map<String, dynamic> json) => EhFiles(
files: (json).map(
(k, e) => MapEntry(
@@ -52,4 +52,7 @@ class EhFiles {
.toList()),
),
);
void merge(EhFiles another) {
files.addAll(another.files);
}
}

View File

@@ -239,10 +239,10 @@ class GMetaSearchInfo {
}
class GalleryThumbnails {
const GalleryThumbnails({
GalleryThumbnails({
required this.thumbnails,
});
final Map<int, ApiResult<ExtendedPMeta>> thumbnails;
Map<int, ApiResult<ExtendedPMeta>> thumbnails;
factory GalleryThumbnails.fromJson(Map<String, dynamic> json) =>
GalleryThumbnails(
thumbnails: json.map((key, value) => MapEntry(
@@ -251,4 +251,17 @@ class GalleryThumbnails {
value as Map<String, dynamic>,
(json) =>
ExtendedPMeta.fromJson(json as Map<String, dynamic>)))));
void merge(GalleryThumbnails another) {
another.thumbnails.forEach((key, value) {
if (thumbnails.containsKey(key)) {
if (value.ok) {
thumbnails[key] = value;
} else if (!thumbnails[key]!.ok) {
thumbnails[key] = value;
}
} else {
thumbnails[key] = value;
}
});
}
}