mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
fix: search (#1412)
This commit is contained in:
committed by
GitHub
parent
e1944b0c8d
commit
4e15422d2d
@@ -50,6 +50,34 @@ abstract class DebounceStreamState<T extends StatefulWidget, S> extends State<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BaseSearchController extends GetxController {
|
||||||
|
final historyList = List<String>.from(
|
||||||
|
GStorage.historyWord.get('cacheList') ?? [],
|
||||||
|
).obs;
|
||||||
|
|
||||||
|
late final Rx<LoadingState<SearchTrendingData>> trendingState;
|
||||||
|
|
||||||
|
final recordSearchHistory = Pref.recordSearchHistory.obs;
|
||||||
|
final searchSuggestion = Pref.searchSuggestion;
|
||||||
|
final enableTrending = Pref.enableTrending;
|
||||||
|
final enableSearchRcmd = Pref.enableSearchRcmd;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
if (enableTrending) {
|
||||||
|
trendingState = LoadingState<SearchTrendingData>.loading().obs;
|
||||||
|
queryTrendingList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取热搜关键词
|
||||||
|
Future<void> queryTrendingList() async {
|
||||||
|
trendingState.value = await SearchHttp.searchTrending(limit: 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SSearchController extends GetxController
|
class SSearchController extends GetxController
|
||||||
with DebounceStreamMixin<String> {
|
with DebounceStreamMixin<String> {
|
||||||
SSearchController(this.tag);
|
SSearchController(this.tag);
|
||||||
@@ -57,6 +85,7 @@ class SSearchController extends GetxController
|
|||||||
|
|
||||||
final searchFocusNode = FocusNode();
|
final searchFocusNode = FocusNode();
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
|
final _baseCtr = Get.putOrFind(BaseSearchController.new);
|
||||||
|
|
||||||
String? hintText;
|
String? hintText;
|
||||||
|
|
||||||
@@ -66,21 +95,24 @@ class SSearchController extends GetxController
|
|||||||
final RxBool showUidBtn = false.obs;
|
final RxBool showUidBtn = false.obs;
|
||||||
|
|
||||||
// history
|
// history
|
||||||
final RxBool recordSearchHistory = Pref.recordSearchHistory.obs;
|
RxBool get recordSearchHistory => _baseCtr.recordSearchHistory;
|
||||||
late final RxList<String> historyList;
|
RxList<String> get historyList => _baseCtr.historyList;
|
||||||
|
|
||||||
// suggestion
|
// suggestion
|
||||||
final bool searchSuggestion = Pref.searchSuggestion;
|
bool get searchSuggestion => _baseCtr.searchSuggestion;
|
||||||
late final RxList<SearchSuggestItem> searchSuggestList;
|
late final RxList<SearchSuggestItem> searchSuggestList;
|
||||||
|
|
||||||
// trending
|
// trending
|
||||||
final bool enableTrending = Pref.enableTrending;
|
bool get enableTrending => _baseCtr.enableTrending;
|
||||||
late final Rx<LoadingState<SearchTrendingData>> trendingState;
|
Rx<LoadingState<SearchTrendingData>> get trendingState =>
|
||||||
|
_baseCtr.trendingState;
|
||||||
|
|
||||||
// rcmd
|
// rcmd
|
||||||
final bool enableSearchRcmd = Pref.enableSearchRcmd;
|
bool get enableSearchRcmd => _baseCtr.enableSearchRcmd;
|
||||||
late final Rx<LoadingState<SearchRcmdData>> recommendData;
|
late final Rx<LoadingState<SearchRcmdData>> recommendData;
|
||||||
|
|
||||||
|
Future<void> Function() get queryTrendingList => _baseCtr.queryTrendingList;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@@ -91,20 +123,11 @@ class SSearchController extends GetxController
|
|||||||
controller.text = text;
|
controller.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
historyList = List<String>.from(
|
|
||||||
GStorage.historyWord.get('cacheList') ?? [],
|
|
||||||
).obs;
|
|
||||||
|
|
||||||
if (searchSuggestion) {
|
if (searchSuggestion) {
|
||||||
subInit();
|
subInit();
|
||||||
searchSuggestList = <SearchSuggestItem>[].obs;
|
searchSuggestList = <SearchSuggestItem>[].obs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enableTrending) {
|
|
||||||
trendingState = LoadingState<SearchTrendingData>.loading().obs;
|
|
||||||
queryTrendingList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableSearchRcmd) {
|
if (enableSearchRcmd) {
|
||||||
recommendData = LoadingState<SearchRcmdData>.loading().obs;
|
recommendData = LoadingState<SearchRcmdData>.loading().obs;
|
||||||
queryRecommendList();
|
queryRecommendList();
|
||||||
@@ -176,11 +199,6 @@ class SSearchController extends GetxController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取热搜关键词
|
|
||||||
Future<void> queryTrendingList() async {
|
|
||||||
trendingState.value = await SearchHttp.searchTrending(limit: 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> queryRecommendList() async {
|
Future<void> queryRecommendList() async {
|
||||||
recommendData.value = await SearchHttp.searchRecommend();
|
recommendData.value = await SearchHttp.searchRecommend();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,10 +203,7 @@ class _SearchPageState extends State<SearchPage> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 34,
|
height: 34,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () => Get.toNamed(
|
onPressed: () => Get.toNamed('/searchTrending'),
|
||||||
'/searchTrending',
|
|
||||||
parameters: {'tag': _tag},
|
|
||||||
),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:get/get.dart';
|
|||||||
class SearchResultController extends GetxController {
|
class SearchResultController extends GetxController {
|
||||||
String keyword = Get.parameters['keyword'] ?? '';
|
String keyword = Get.parameters['keyword'] ?? '';
|
||||||
|
|
||||||
RxList<int> count = List.generate(SearchType.values.length, (_) => -1).obs;
|
RxList<int> count = List.filled(SearchType.values.length, -1).obs;
|
||||||
|
|
||||||
RxInt toTopIndex = (-1).obs;
|
RxInt toTopIndex = (-1).obs;
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ class SearchTrendingPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SearchTrendingPageState extends State<SearchTrendingPage> {
|
class _SearchTrendingPageState extends State<SearchTrendingPage> {
|
||||||
final _controller = Get.put(
|
final _controller = Get.putOrFind(SearchTrendingController.new);
|
||||||
SearchTrendingController(),
|
|
||||||
tag: Get.parameters['tag'],
|
|
||||||
);
|
|
||||||
|
|
||||||
late double _offset;
|
late double _offset;
|
||||||
final RxDouble _scrollRatio = 0.0.obs;
|
final RxDouble _scrollRatio = 0.0.obs;
|
||||||
|
|||||||
Reference in New Issue
Block a user