history feature

This commit is contained in:
wgh19
2024-05-15 12:49:58 +08:00
parent 51bff418c7
commit e59d15f685
3 changed files with 76 additions and 0 deletions

View File

@@ -418,4 +418,18 @@ class Network {
return Res.error(res.errorMessage);
}
}
Future<Res<List<Illust>>> getHistory(int page) async {
String param = "";
if(page > 1) {
param = "?offset=${30*(page-1)}";
}
var res = await apiGet("/v1/user/browsing-history/illusts$param");
if (res.success) {
return Res((res.data["illusts"] as List)
.map((e) => Illust.fromJson(e)).toList());
} else {
return Res.error(res.errorMessage);
}
}
}

55
lib/pages/history.dart Normal file
View File

@@ -0,0 +1,55 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:pixes/appdata.dart';
import 'package:pixes/components/loading.dart';
import 'package:pixes/components/title_bar.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/network/models.dart';
import 'package:pixes/network/network.dart';
import 'package:pixes/utils/translation.dart';
import '../components/illust_widget.dart';
class HistoryPage extends StatefulWidget {
const HistoryPage({super.key});
@override
State<HistoryPage> createState() => _HistoryPageState();
}
class _HistoryPageState extends MultiPageLoadingState<HistoryPage, Illust> {
@override
Widget buildContent(BuildContext context, final List<Illust> data) {
return Column(
children: [
TitleBar(title: "History".tl),
Expanded(
child: LayoutBuilder(builder: (context, constrains){
return MasonryGridView.builder(
padding: const EdgeInsets.symmetric(horizontal: 8)
+ EdgeInsets.only(bottom: context.padding.bottom),
gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 240,
),
itemCount: data.length,
itemBuilder: (context, index) {
if(index == data.length - 1){
nextPage();
}
return IllustWidget(data[index]);
},
);
}),
)
],
);
}
@override
Future<Res<List<Illust>>> loadData(page) {
if(appdata.account?.user.isPremium != true) {
return Future.value(Res.error("Premium Required".tl));
}
return Network().getHistory(page);
}
}

View File

@@ -10,6 +10,7 @@ import "package:pixes/network/network.dart";
import "package:pixes/pages/bookmarks.dart";
import "package:pixes/pages/downloaded_page.dart";
import "package:pixes/pages/following_artworks.dart";
import "package:pixes/pages/history.dart";
import "package:pixes/pages/ranking.dart";
import "package:pixes/pages/recommendation_page.dart";
import "package:pixes/pages/login_page.dart";
@@ -129,6 +130,11 @@ class _MainPageState extends State<MainPage> with WindowListener {
title: Text('Following'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.history, size: 20),
title: Text('History'.tl),
body: const SizedBox.shrink(),
),
PaneItem(
icon: const Icon(MdIcons.leaderboard_outlined, size: 20),
title: Text('Ranking'.tl),
@@ -166,6 +172,7 @@ class _MainPageState extends State<MainPage> with WindowListener {
() => const RecommendationPage(),
() => const BookMarkedArtworkPage(),
() => const FollowingArtworksPage(),
() => const HistoryPage(),
() => const RankingPage(),
() => const SettingsPage(),
];