diff --git a/lib/network/network.dart b/lib/network/network.dart index 4ebbb99..2e8ea40 100644 --- a/lib/network/network.dart +++ b/lib/network/network.dart @@ -336,4 +336,15 @@ class Network { return Res.error(res.errorMessage); } } + + Future>> getFollowingArtworks(String restrict, [String? nextUrl]) async { + var res = await apiGet(nextUrl ?? "/v2/illust/follow?restrict=$restrict"); + 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); + } + } } diff --git a/lib/pages/following_artworks.dart b/lib/pages/following_artworks.dart new file mode 100644 index 0000000..615368b --- /dev/null +++ b/lib/pages/following_artworks.dart @@ -0,0 +1,95 @@ +import 'package:fluent_ui/fluent_ui.dart'; +import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; +import 'package:pixes/foundation/app.dart'; +import 'package:pixes/utils/translation.dart'; + +import '../components/illust_widget.dart'; +import '../components/loading.dart'; +import '../components/segmented_button.dart'; +import '../network/network.dart'; + +class FollowingArtworksPage extends StatefulWidget { + const FollowingArtworksPage({super.key}); + + @override + State createState() => _FollowingArtworksPageState(); +} + +class _FollowingArtworksPageState extends State { + String restrict = "all"; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + buildTab(), + Expanded( + child: _OneFollowingPage(restrict, key: Key(restrict),), + ) + ], + ); + } + + Widget buildTab() { + return SegmentedButton( + options: [ + SegmentedButtonOption("all", "All".tl), + SegmentedButtonOption("public", "Public".tl), + SegmentedButtonOption("private", "Private".tl), + ], + onPressed: (key) { + if(key != restrict) { + setState(() { + restrict = key; + }); + } + }, + value: restrict, + ).padding(const EdgeInsets.symmetric(vertical: 8, horizontal: 8)); + } +} + +class _OneFollowingPage extends StatefulWidget { + const _OneFollowingPage(this.restrict, {super.key}); + + final String restrict; + + @override + State<_OneFollowingPage> createState() => _OneFollowingPageState(); +} + +class _OneFollowingPageState extends MultiPageLoadingState<_OneFollowingPage, Illust> { + @override + Widget buildContent(BuildContext context, final List data) { + return LayoutBuilder(builder: (context, constrains){ + return MasonryGridView.builder( + gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 240, + ), + itemCount: data.length, + itemBuilder: (context, index) { + if(index == data.length - 1){ + nextPage(); + } + return IllustWidget(data[index]); + }, + ); + }); + } + + String? nextUrl; + + @override + Future>> loadData(page) async{ + if(nextUrl == "end") { + return Res.error("No more data"); + } + var res = await Network().getFollowingArtworks(widget.restrict, nextUrl); + if(!res.error) { + nextUrl = res.subData; + nextUrl ??= "end"; + } + return res; + } +} + diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 24026d9..0922f51 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -9,6 +9,7 @@ import "package:pixes/foundation/app.dart"; import "package:pixes/network/network.dart"; import "package:pixes/pages/bookmarks.dart"; import "package:pixes/pages/explore_page.dart"; +import "package:pixes/pages/following_artworks.dart"; import "package:pixes/pages/recommendation_page.dart"; import "package:pixes/pages/login_page.dart"; import "package:pixes/pages/search_page.dart"; @@ -99,6 +100,7 @@ class _MainPageState extends State with WindowListener { title: Text('Search'.tl), body: const SizedBox.shrink(), ), + PaneItemSeparator(), PaneItemHeader(header: Text("Artwork".tl).paddingVertical(4).paddingLeft(8)), PaneItem( icon: const Icon(MdIcons.star_border, size: 20,), @@ -110,6 +112,11 @@ class _MainPageState extends State with WindowListener { title: Text('Bookmarks'.tl), body: const SizedBox.shrink(), ), + PaneItem( + icon: const Icon(MdIcons.interests_outlined, size: 20), + title: Text('Following'.tl), + body: const SizedBox.shrink(), + ), PaneItemSeparator(), PaneItem( icon: const Icon(MdIcons.explore_outlined, size: 20), @@ -138,6 +145,7 @@ class _MainPageState extends State with WindowListener { () => const SearchPage(), () => const RecommendationPage(), () => const BookMarkedArtworkPage(), + () => const FollowingArtworksPage(), () => const ExplorePage(), () => const SettingsPage(), ]; diff --git a/lib/pages/user_info_page.dart b/lib/pages/user_info_page.dart index abe6350..3880d63 100644 --- a/lib/pages/user_info_page.dart +++ b/lib/pages/user_info_page.dart @@ -106,7 +106,7 @@ class _UserInfoPageState extends LoadingState { child: Column( children: [ buildHeader("Infomation".tl), - buildItem(icon: MdIcons.comment_outlined, title: "Comment".tl, content: data!.comment), + buildItem(icon: MdIcons.comment_outlined, title: "Introduction".tl, content: data!.comment), buildItem(icon: MdIcons.cake_outlined, title: "Birthday".tl, content: data!.birth), buildItem(icon: MdIcons.location_city_outlined, title: "Region", content: data!.region), buildItem(icon: MdIcons.work_outline, title: "Job".tl, content: data!.job),