fix: Search in spaces view

This commit is contained in:
krille-chan 2024-03-10 16:26:40 +01:00
parent c842e3454b
commit 6073b46cfc
No known key found for this signature in database
3 changed files with 29 additions and 11 deletions

View file

@ -266,7 +266,7 @@ class ChatListController extends State<ChatList>
});
}
void onSearchEnter(String text) {
void onSearchEnter(String text, {bool globalSearch = true}) {
if (text.isEmpty) {
cancelSearch(unfocus: false);
return;
@ -276,7 +276,9 @@ class ChatListController extends State<ChatList>
isSearchMode = true;
});
_coolDown?.cancel();
_coolDown = Timer(const Duration(milliseconds: 500), _search);
if (globalSearch) {
_coolDown = Timer(const Duration(milliseconds: 500), _search);
}
}
void startSearch() {

View file

@ -9,8 +9,13 @@ import '../../widgets/matrix.dart';
class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
final ChatListController controller;
final bool globalSearch;
const ChatListHeader({super.key, required this.controller});
const ChatListHeader({
super.key,
required this.controller,
this.globalSearch = true,
});
@override
Widget build(BuildContext context) {
@ -47,7 +52,10 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
controller: controller.searchController,
focusNode: controller.searchFocusNode,
textInputAction: TextInputAction.search,
onChanged: controller.onSearchEnter,
onChanged: (text) => controller.onSearchEnter(
text,
globalSearch: globalSearch,
),
decoration: InputDecoration(
fillColor: Theme.of(context).colorScheme.secondaryContainer,
border: OutlineInputBorder(
@ -79,7 +87,7 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
.onPrimaryContainer,
),
),
suffixIcon: controller.isSearchMode
suffixIcon: controller.isSearchMode && globalSearch
? controller.isSearching
? const Padding(
padding: EdgeInsets.symmetric(

View file

@ -279,10 +279,17 @@ class _SpaceViewState extends State<SpaceView> {
if (activeSpaceId == null) {
final rootSpaces = allSpaces
.where(
(space) => !allSpaces.any(
(parentSpace) => parentSpace.spaceChildren
.any((child) => child.roomId == space.id),
),
(space) =>
!allSpaces.any(
(parentSpace) => parentSpace.spaceChildren
.any((child) => child.roomId == space.id),
) &&
space
.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!))
.toLowerCase()
.contains(
widget.controller.searchController.text.toLowerCase(),
),
)
.toList();
@ -347,7 +354,7 @@ class _SpaceViewState extends State<SpaceView> {
child: CustomScrollView(
controller: widget.scrollController,
slivers: [
ChatListHeader(controller: widget.controller),
ChatListHeader(controller: widget.controller, globalSearch: false),
SliverAppBar(
automaticallyImplyLeading: false,
primary: false,
@ -490,7 +497,8 @@ class _SpaceViewState extends State<SpaceView> {
L10n.of(context)!.chat;
if (widget.controller.isSearchMode &&
!name.toLowerCase().contains(
widget.controller.searchController.text,
widget.controller.searchController.text
.toLowerCase(),
)) {
return const SizedBox.shrink();
}