|
|
|
@ -21,6 +21,25 @@ class ImmichSearchBar extends HookConsumerWidget
|
|
|
|
final searchTermController = useTextEditingController(text: "");
|
|
|
|
final searchTermController = useTextEditingController(text: "");
|
|
|
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
|
|
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
focusSearch() {
|
|
|
|
|
|
|
|
searchTermController.clear();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).getSuggestedSearchTerms();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).enableSearch();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchFocusNode.requestFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
|
|
|
|
() {
|
|
|
|
|
|
|
|
searchFocusNotifier.addListener(focusSearch);
|
|
|
|
|
|
|
|
return () {
|
|
|
|
|
|
|
|
searchFocusNotifier.removeListener(focusSearch);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
[],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return AppBar(
|
|
|
|
return AppBar(
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
leading: isSearchEnabled
|
|
|
|
leading: isSearchEnabled
|
|
|
|
@ -40,14 +59,7 @@ class ImmichSearchBar extends HookConsumerWidget
|
|
|
|
controller: searchTermController,
|
|
|
|
controller: searchTermController,
|
|
|
|
focusNode: searchFocusNode,
|
|
|
|
focusNode: searchFocusNode,
|
|
|
|
autofocus: false,
|
|
|
|
autofocus: false,
|
|
|
|
onTap: () {
|
|
|
|
onTap: focusSearch,
|
|
|
|
searchTermController.clear();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).getSuggestedSearchTerms();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).enableSearch();
|
|
|
|
|
|
|
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchFocusNode.requestFocus();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmitted: (searchTerm) {
|
|
|
|
onSubmitted: (searchTerm) {
|
|
|
|
onSubmitted(searchTerm);
|
|
|
|
onSubmitted(searchTerm);
|
|
|
|
searchTermController.clear();
|
|
|
|
searchTermController.clear();
|
|
|
|
@ -75,3 +87,13 @@ class ImmichSearchBar extends HookConsumerWidget
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Used to focus search from outside this widget.
|
|
|
|
|
|
|
|
// For example when double pressing the search nav icon.
|
|
|
|
|
|
|
|
final searchFocusNotifier = SearchFocusNotifier();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchFocusNotifier with ChangeNotifier {
|
|
|
|
|
|
|
|
void requestFocus() {
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|