Update Galleries

This commit is contained in:
2023-09-15 15:39:01 +08:00
parent 932c56a377
commit dae5e13bd8
6 changed files with 42 additions and 7 deletions

View File

@@ -150,6 +150,8 @@ abstract class _EHApi {
@Query("offset") int? offset,
@Query("limit") int? limit,
@Query("sort_by_gid") bool? sortByGid,
@Query("uploader") String? uploader,
@Query("tag") String? tag,
@CancelRequest() CancelToken? cancel});
@GET('/tag/{id}')

View File

@@ -531,6 +531,8 @@ class __EHApi implements _EHApi {
int? offset,
int? limit,
bool? sortByGid,
String? uploader,
String? tag,
CancelToken? cancel,
}) async {
const _extra = <String, dynamic>{};
@@ -539,6 +541,8 @@ class __EHApi implements _EHApi {
r'offset': offset,
r'limit': limit,
r'sort_by_gid': sortByGid,
r'uploader': uploader,
r'tag': tag,
};
queryParameters.removeWhere((k, v) => v == null);
final _headers = <String, dynamic>{};

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../api/gallery.dart';
@@ -16,7 +17,13 @@ class TagTooltip extends StatelessWidget {
@override
Widget build(BuildContext context) {
final name = _getTag(tag);
final t = SelectableText(name);
final t = InkWell(
onTap: () {
context.pushNamed("/galleries", queryParameters: {
"tag": [tag.tag]
});
},
child: Text(name));
return tag.intro != null && tag.intro!.isNotEmpty
? Tooltip(
message: tag.intro!,

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import '../api/gallery.dart';
import '../globals.dart';
import '../main.dart';
@@ -73,7 +74,13 @@ class _TagsPanel extends State<TagsPanel> {
),
child: stt
? TagTooltip(ta[index - 1]!)
: SelectableText(ta[index - 1]!.tag));
: InkWell(
onTap: () {
context.pushNamed("/galleries", queryParameters: {
"tag": [ta[index - 1]!.tag]
});
},
child: Text(ta[index - 1]!.tag)));
}
}));
});

View File

@@ -10,8 +10,11 @@ import 'globals.dart';
final _log = Logger("GalleriesPage");
class GalleriesPage extends StatefulWidget {
const GalleriesPage({Key? key, this.sortByGid}) : super(key: key);
const GalleriesPage({Key? key, this.sortByGid, this.uploader, this.tag})
: super(key: key);
final SortByGid? sortByGid;
final String? uploader;
final String? tag;
static const String routeName = '/galleries';
@@ -30,7 +33,11 @@ class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
Future<void> _fetchPage(int pageKey) async {
try {
final list = (await api.listGalleries(
offset: pageKey, limit: _pageSize, sortByGid: _sortByGid))
offset: pageKey,
limit: _pageSize,
sortByGid: _sortByGid,
uploader: widget.uploader,
tag: widget.tag))
.unwrap();
final isLastPage = list.length < _pageSize;
if (isLastPage) {
@@ -73,9 +80,14 @@ class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
}).catchError((error) {
_log.warning("Failed to save sortByGid to prefs:", error);
});
context.pushReplacementNamed("/galleries", queryParameters: {
var queryParameters = {
"sortByGid": [v!.index.toString()],
});
"tag": [widget.tag ?? ""],
"uploader": [widget.uploader ?? ""],
};
queryParameters.removeWhere((k, v) => v[0].isEmpty);
context.pushReplacementNamed("/galleries",
queryParameters: queryParameters);
}
},
label: Text(AppLocalizations.of(context)!.sortByGid,

View File

@@ -55,7 +55,10 @@ final _router = GoRouter(
} catch (e) {
_routerLog.warning("Failed to load sortByGid from prefs:", e);
}
return GalleriesPage(sortByGid: sortByGid);
final tag = state.uri.queryParameters["tag"];
final uploader = state.uri.queryParameters["uploader"];
return GalleriesPage(
sortByGid: sortByGid, tag: tag, uploader: uploader);
}),
GoRoute(
path: GalleryPage.routeName,