mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-25 03:26:22 +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
|
||||
with DebounceStreamMixin<String> {
|
||||
SSearchController(this.tag);
|
||||
@@ -57,6 +85,7 @@ class SSearchController extends GetxController
|
||||
|
||||
final searchFocusNode = FocusNode();
|
||||
final controller = TextEditingController();
|
||||
final _baseCtr = Get.putOrFind(BaseSearchController.new);
|
||||
|
||||
String? hintText;
|
||||
|
||||
@@ -66,21 +95,24 @@ class SSearchController extends GetxController
|
||||
final RxBool showUidBtn = false.obs;
|
||||
|
||||
// history
|
||||
final RxBool recordSearchHistory = Pref.recordSearchHistory.obs;
|
||||
late final RxList<String> historyList;
|
||||
RxBool get recordSearchHistory => _baseCtr.recordSearchHistory;
|
||||
RxList<String> get historyList => _baseCtr.historyList;
|
||||
|
||||
// suggestion
|
||||
final bool searchSuggestion = Pref.searchSuggestion;
|
||||
bool get searchSuggestion => _baseCtr.searchSuggestion;
|
||||
late final RxList<SearchSuggestItem> searchSuggestList;
|
||||
|
||||
// trending
|
||||
final bool enableTrending = Pref.enableTrending;
|
||||
late final Rx<LoadingState<SearchTrendingData>> trendingState;
|
||||
bool get enableTrending => _baseCtr.enableTrending;
|
||||
Rx<LoadingState<SearchTrendingData>> get trendingState =>
|
||||
_baseCtr.trendingState;
|
||||
|
||||
// rcmd
|
||||
final bool enableSearchRcmd = Pref.enableSearchRcmd;
|
||||
bool get enableSearchRcmd => _baseCtr.enableSearchRcmd;
|
||||
late final Rx<LoadingState<SearchRcmdData>> recommendData;
|
||||
|
||||
Future<void> Function() get queryTrendingList => _baseCtr.queryTrendingList;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -91,20 +123,11 @@ class SSearchController extends GetxController
|
||||
controller.text = text;
|
||||
}
|
||||
|
||||
historyList = List<String>.from(
|
||||
GStorage.historyWord.get('cacheList') ?? [],
|
||||
).obs;
|
||||
|
||||
if (searchSuggestion) {
|
||||
subInit();
|
||||
searchSuggestList = <SearchSuggestItem>[].obs;
|
||||
}
|
||||
|
||||
if (enableTrending) {
|
||||
trendingState = LoadingState<SearchTrendingData>.loading().obs;
|
||||
queryTrendingList();
|
||||
}
|
||||
|
||||
if (enableSearchRcmd) {
|
||||
recommendData = LoadingState<SearchRcmdData>.loading().obs;
|
||||
queryRecommendList();
|
||||
@@ -176,11 +199,6 @@ class SSearchController extends GetxController
|
||||
}
|
||||
}
|
||||
|
||||
// 获取热搜关键词
|
||||
Future<void> queryTrendingList() async {
|
||||
trendingState.value = await SearchHttp.searchTrending(limit: 10);
|
||||
}
|
||||
|
||||
Future<void> queryRecommendList() async {
|
||||
recommendData.value = await SearchHttp.searchRecommend();
|
||||
}
|
||||
|
||||
@@ -203,10 +203,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
SizedBox(
|
||||
height: 34,
|
||||
child: TextButton(
|
||||
onPressed: () => Get.toNamed(
|
||||
'/searchTrending',
|
||||
parameters: {'tag': _tag},
|
||||
),
|
||||
onPressed: () => Get.toNamed('/searchTrending'),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:get/get.dart';
|
||||
class SearchResultController extends GetxController {
|
||||
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;
|
||||
|
||||
|
||||
@@ -24,10 +24,7 @@ class SearchTrendingPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SearchTrendingPageState extends State<SearchTrendingPage> {
|
||||
final _controller = Get.put(
|
||||
SearchTrendingController(),
|
||||
tag: Get.parameters['tag'],
|
||||
);
|
||||
final _controller = Get.putOrFind(SearchTrendingController.new);
|
||||
|
||||
late double _offset;
|
||||
final RxDouble _scrollRatio = 0.0.obs;
|
||||
|
||||
Reference in New Issue
Block a user