diff --git a/lib/appdata.dart b/lib/appdata.dart index 87019de..82ad8df 100644 --- a/lib/appdata.dart +++ b/lib/appdata.dart @@ -7,6 +7,8 @@ import 'network/models.dart'; class _Appdata { Account? account; + var searchOptions = SearchOptions(); + void writeData() async { await File("${App.dataPath}/account.json") .writeAsString(jsonEncode(account)); diff --git a/lib/components/loading.dart b/lib/components/loading.dart index e9de33b..7b92e71 100644 --- a/lib/components/loading.dart +++ b/lib/components/loading.dart @@ -3,7 +3,7 @@ import 'package:pixes/foundation/app.dart'; import 'package:pixes/network/res.dart'; abstract class LoadingState extends State{ - bool isLoading = true; + bool isLoading = false; S? data; @@ -13,22 +13,29 @@ abstract class LoadingState extends Widget buildContent(BuildContext context, S data); + @override + @mustCallSuper + void initState() { + isLoading = true; + loadData().then((value) { + if(value.success) { + setState(() { + isLoading = false; + data = value.data; + }); + } else { + setState(() { + isLoading = false; + error = value.errorMessage!; + }); + } + }); + super.initState(); + } + @override Widget build(BuildContext context) { if(isLoading){ - loadData().then((value) { - if(value.success) { - setState(() { - isLoading = false; - data = value.data; - }); - } else { - setState(() { - isLoading = false; - error = value.errorMessage!; - }); - } - }); return const Center( child: ProgressRing(), ); diff --git a/lib/components/page_route.dart b/lib/components/page_route.dart index 8400606..5a6bee5 100644 --- a/lib/components/page_route.dart +++ b/lib/components/page_route.dart @@ -344,7 +344,7 @@ class SideBarRoute extends PopupRoute { @override Duration get transitionDuration => const Duration(milliseconds: 200); - static bool _isPopGestureEnabled(PopupRoute route) { + static bool _isPopGestureEnabled(PopupRoute route) { if (route.isFirst || route.willHandlePopInternally || route.popDisposition == RoutePopDisposition.doNotPop || diff --git a/lib/network/models.dart b/lib/network/models.dart index b3478d3..7e5e376 100644 --- a/lib/network/models.dart +++ b/lib/network/models.dart @@ -1,3 +1,5 @@ +import 'package:pixes/appdata.dart'; + class Account { String accessToken; String refreshToken; @@ -213,3 +215,74 @@ class TrendingTag { TrendingTag(this.tag, this.illust); } + +enum KeywordMatchType { + tagsPartialMatches("Tags partial matches"), + tagsExactMatch("Tags exact match"), + titleOrDescriptionSearch("Title or description search"); + + final String text; + + const KeywordMatchType(this.text); + + @override + toString() => text; +} + +enum FavoriteNumber { + unlimited(-1), + f500(500), + f1000(1000), + f2000(2000), + f5000(5000), + f7500(7500), + f10000(10000), + f20000(20000), + f50000(50000), + f100000(100000); + + final int number; + const FavoriteNumber(this.number); + + @override + toString() => this == FavoriteNumber.unlimited ? "Unlimited" : "$number Bookmarks"; +} + +enum SearchSort { + newToOld, + oldToNew, + popular; + + @override + toString() { + if(this == SearchSort.popular) { + return appdata.account?.user.isPremium == true ? "Popular" : "Popular(limited)"; + } else if(this == SearchSort.newToOld) { + return "New to old"; + } else { + return "Old to new"; + } + } +} + +enum AgeLimit { + unlimited("Unlimited"), + allAges("All ages"), + r18("R18"); + + final String text; + + const AgeLimit(this.text); + + @override + toString() => text; +} + +class SearchOptions { + KeywordMatchType matchType = KeywordMatchType.tagsPartialMatches; + FavoriteNumber favoriteNumber = FavoriteNumber.unlimited; + SearchSort sort = SearchSort.newToOld; + DateTime? startTime; + DateTime? endTime; + AgeLimit ageLimit = AgeLimit.unlimited; +} diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 834c451..0182fe5 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -31,7 +31,7 @@ class MainPage extends StatefulWidget { class _MainPageState extends State with WindowListener { final navigatorKey = GlobalKey(); - int index = 1; + int index = 2; int windowButtonKey = 0; diff --git a/lib/pages/search_page.dart b/lib/pages/search_page.dart index 39621cf..3f5b377 100644 --- a/lib/pages/search_page.dart +++ b/lib/pages/search_page.dart @@ -1,5 +1,6 @@ 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/page_route.dart'; import 'package:pixes/foundation/app.dart'; @@ -246,9 +247,83 @@ class _SearchSettingsState extends State { child: Column( children: [ Padding( - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12), + padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12), child: Text("Search Settings".tl, style: const TextStyle(fontSize: 18),), ).toAlign(Alignment.centerLeft), + buildItem(title: "Match".tl, child: DropDownButton( + title: Text(appdata.searchOptions.matchType.toString()), + items: KeywordMatchType.values.map((e) => + MenuFlyoutItem( + text: Text(e.toString()), + onPressed: () => setState(() => appdata.searchOptions.matchType = e) + ) + ).toList(), + )), + buildItem(title: "Favorite number".tl, child: DropDownButton( + title: Text(appdata.searchOptions.favoriteNumber.toString()), + items: FavoriteNumber.values.map((e) => + MenuFlyoutItem( + text: Text(e.toString()), + onPressed: () => setState(() => appdata.searchOptions.favoriteNumber = e) + ) + ).toList(), + )), + buildItem(title: "Sort".tl, child: DropDownButton( + title: Text(appdata.searchOptions.sort.toString()), + items: SearchSort.values.map((e) => + MenuFlyoutItem( + text: Text(e.toString()), + onPressed: () => setState(() => appdata.searchOptions.sort = e) + ) + ).toList(), + )), + Card( + padding: EdgeInsets.zero, + margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + child: SizedBox( + width: double.infinity, + child: Column( + children: [ + const Text("Start Time", style: TextStyle(fontSize: 16),) + .paddingVertical(8) + .toAlign(Alignment.centerLeft) + .paddingLeft(16), + DatePicker( + selected: appdata.searchOptions.startTime, + onChanged: (t) => setState(() => appdata.searchOptions.startTime = t), + ), + const SizedBox(height: 8,) + ], + ), + )), + Card( + padding: EdgeInsets.zero, + margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + child: SizedBox( + width: double.infinity, + child: Column( + children: [ + const Text("End Time", style: TextStyle(fontSize: 16),) + .paddingVertical(8) + .toAlign(Alignment.centerLeft) + .paddingLeft(16), + DatePicker( + selected: appdata.searchOptions.endTime, + onChanged: (t) => setState(() => appdata.searchOptions.endTime = t), + ), + const SizedBox(height: 8,) + ], + ), + )), + buildItem(title: "Age limit".tl, child: DropDownButton( + title: Text(appdata.searchOptions.ageLimit.toString()), + items: AgeLimit.values.map((e) => + MenuFlyoutItem( + text: Text(e.toString()), + onPressed: () => setState(() => appdata.searchOptions.ageLimit = e) + ) + ).toList(), + )), ], ), );