mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
View a user's public bookmarks
This commit is contained in:
@@ -233,6 +233,18 @@ class Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Res<List<Illust>>> getUserBookmarks(String uid, [String? nextUrl]) async {
|
||||||
|
var res = await apiGet(nextUrl ??
|
||||||
|
"/v1/user/bookmarks/illust?user_id=$uid&restrict=public");
|
||||||
|
if (res.success) {
|
||||||
|
return Res(
|
||||||
|
(res.data["illusts"] as List).map((e) => Illust.fromJson(e)).toList(),
|
||||||
|
subData: res.data["next_url"]);
|
||||||
|
} else {
|
||||||
|
return Res.error(res.errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<Res<bool>> addBookmark(String id, String method,
|
Future<Res<bool>> addBookmark(String id, String method,
|
||||||
[String type = "public"]) async {
|
[String type = "public"]) async {
|
||||||
var res = method == "add"
|
var res = method == "add"
|
||||||
|
@@ -5,6 +5,7 @@ import 'package:pixes/appdata.dart';
|
|||||||
import 'package:pixes/components/batch_download.dart';
|
import 'package:pixes/components/batch_download.dart';
|
||||||
import 'package:pixes/components/loading.dart';
|
import 'package:pixes/components/loading.dart';
|
||||||
import 'package:pixes/components/md.dart';
|
import 'package:pixes/components/md.dart';
|
||||||
|
import 'package:pixes/components/segmented_button.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/foundation/image_provider.dart';
|
import 'package:pixes/foundation/image_provider.dart';
|
||||||
import 'package:pixes/network/network.dart';
|
import 'package:pixes/network/network.dart';
|
||||||
@@ -26,6 +27,8 @@ class UserInfoPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
||||||
|
int page = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildContent(BuildContext context, UserDetails data) {
|
Widget buildContent(BuildContext context, UserDetails data) {
|
||||||
return ScaffoldPage(
|
return ScaffoldPage(
|
||||||
@@ -33,13 +36,8 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
slivers: [
|
slivers: [
|
||||||
buildUser(),
|
buildUser(),
|
||||||
buildInformation(),
|
buildInformation(),
|
||||||
SliverToBoxAdapter(
|
buildArtworkHeader(),
|
||||||
child: buildHeader(
|
_UserArtworks(data.id.toString(), page, key: ValueKey(data.id + page),),
|
||||||
"Artworks",
|
|
||||||
action: BatchDownloadButton(
|
|
||||||
request: () => Network().getUserIllusts(widget.id))
|
|
||||||
),),
|
|
||||||
_UserArtworks(data.id.toString(), key: ValueKey(data.id),),
|
|
||||||
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom)),
|
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -169,6 +167,38 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
).paddingHorizontal(16)).paddingTop(8);
|
).paddingHorizontal(16)).paddingTop(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildArtworkHeader() {
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 38,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
SegmentedButton<int>(
|
||||||
|
options: [
|
||||||
|
SegmentedButtonOption(0, "Artworks".tl),
|
||||||
|
SegmentedButtonOption(1, "Bookmarks".tl),
|
||||||
|
],
|
||||||
|
value: page,
|
||||||
|
onPressed: (value) {
|
||||||
|
setState(() {
|
||||||
|
page = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
BatchDownloadButton(request: () {
|
||||||
|
if(page == 0) {
|
||||||
|
return Network().getUserIllusts(data!.id.toString());
|
||||||
|
} else {
|
||||||
|
return Network().getUserBookmarks(data!.id.toString());
|
||||||
|
}
|
||||||
|
},),
|
||||||
|
],
|
||||||
|
).paddingHorizontal(16)).paddingTop(12),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildInformation() {
|
Widget buildInformation() {
|
||||||
Widget buildItem({IconData? icon, required String title, required String? content, Widget? trailing}) {
|
Widget buildItem({IconData? icon, required String title, required String? content, Widget? trailing}) {
|
||||||
if(content == null || content.isEmpty) {
|
if(content == null || content.isEmpty) {
|
||||||
@@ -226,10 +256,12 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _UserArtworks extends StatefulWidget {
|
class _UserArtworks extends StatefulWidget {
|
||||||
const _UserArtworks(this.uid, {super.key});
|
const _UserArtworks(this.uid, this.type, {super.key});
|
||||||
|
|
||||||
final String uid;
|
final String uid;
|
||||||
|
|
||||||
|
final int type;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_UserArtworks> createState() => _UserArtworksState();
|
State<_UserArtworks> createState() => _UserArtworksState();
|
||||||
}
|
}
|
||||||
@@ -289,7 +321,9 @@ class _UserArtworksState extends MultiPageLoadingState<_UserArtworks, Illust> {
|
|||||||
return Res.error("No more data");
|
return Res.error("No more data");
|
||||||
}
|
}
|
||||||
var res = nextUrl == null
|
var res = nextUrl == null
|
||||||
? await Network().getUserIllusts(widget.uid)
|
? (widget.type == 0
|
||||||
|
? await Network().getUserIllusts(widget.uid)
|
||||||
|
: await Network().getUserBookmarks(widget.uid))
|
||||||
: await Network().getIllustsWithNextUrl(nextUrl!);
|
: await Network().getIllustsWithNextUrl(nextUrl!);
|
||||||
if(!res.error) {
|
if(!res.error) {
|
||||||
nextUrl = res.subData;
|
nextUrl = res.subData;
|
||||||
|
Reference in New Issue
Block a user