mirror of
https://github.com/krille-chan/fluffychat
synced 2024-10-05 13:52:46 +00:00
fix: Search in spaces view
This commit is contained in:
parent
c842e3454b
commit
6073b46cfc
3 changed files with 29 additions and 11 deletions
|
@ -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() {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue