Skip to content

Commit

Permalink
TW-1051: Apply search for forward screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Nov 24, 2023
1 parent 8e7f05c commit 7d82710
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
21 changes: 19 additions & 2 deletions lib/pages/forward/forward.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import 'package:fluffychat/pages/chat/send_file_dialog.dart';
import 'package:fluffychat/pages/forward/forward_view.dart';
import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart';
import 'package:fluffychat/presentation/extensions/client_extension.dart';
import 'package:fluffychat/presentation/mixins/search_recent_chat_mixin.dart';
import 'package:fluffychat/presentation/model/pop_result_from_forward.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:scroll_to_index/scroll_to_index.dart';
Expand All @@ -26,12 +28,11 @@ class Forward extends StatefulWidget {
ForwardController createState() => ForwardController();
}

class ForwardController extends State<Forward> {
class ForwardController extends State<Forward> with SearchRecentChat {
final _forwardMessageInteractor = getIt.get<ForwardMessageInteractor>();

final forwardMessageNotifier = ValueNotifier<Either<Failure, Success>?>(null);

final isShowRecentlyChatsNotifier = ValueNotifier(true);
final isSearchBarShowNotifier = ValueNotifier(false);

StreamSubscription? forwardMessageInteractorStreamSubscription;
Expand All @@ -51,12 +52,19 @@ class ForwardController extends State<Forward> {
void initState() {
super.initState();
sendFromRoomId = widget.sendFromRoomId;
_listenToSearch();
SchedulerBinding.instance.addPostFrameCallback((_) async {
recentlyChatsNotifier.value = filteredRoomsForAll;
});
}

@override
void dispose() {
forwardMessageNotifier.dispose();
isSearchBarShowNotifier.dispose();
recentChatScrollController.dispose();
forwardMessageInteractorStreamSubscription?.cancel();
disposeSearchRecentChat();
super.dispose();
}

Expand Down Expand Up @@ -141,6 +149,15 @@ class ForwardController extends State<Forward> {
context.go('/rooms/${widget.sendFromRoomId}');
}

void _listenToSearch() {
searchTextEditingController.addListener(
() => handleSearchAction(
context: context,
filteredRoomsForAll: filteredRoomsForAll,
),
);
}

@override
Widget build(BuildContext context) => ForwardView(this);
}
Expand Down
16 changes: 11 additions & 5 deletions lib/pages/forward/forward_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart';
import 'package:matrix/matrix.dart';

class ForwardView extends StatelessWidget {
final ForwardController controller;
Expand All @@ -30,6 +31,7 @@ class ForwardView extends StatelessWidget {
child: _ForwardAppBar(
isSearchBarShowNotifier: controller.isSearchBarShowNotifier,
sendFromRoomId: controller.sendFromRoomId,
textEditingController: controller.searchTextEditingController,
),
),
body: WillPopScope(
Expand All @@ -43,12 +45,12 @@ class ForwardView extends StatelessWidget {
child: Column(
children: [
const RecentChatsTitle(),
ValueListenableBuilder<bool>(
valueListenable: controller.isShowRecentlyChatsNotifier,
builder: (context, isShowRecentlyChat, child) {
if (isShowRecentlyChat) {
ValueListenableBuilder<List<Room>>(
valueListenable: controller.recentlyChatsNotifier,
builder: (context, rooms, child) {
if (rooms.isNotEmpty) {
return RecentChatList(
rooms: controller.filteredRoomsForAll,
rooms: rooms,
selectedEventsNotifier: controller.selectedEventsNotifier,
onSelectedChat: (roomId) =>
controller.onSelectChat(roomId),
Expand Down Expand Up @@ -143,12 +145,15 @@ class _ForwardAppBar extends StatelessWidget {
const _ForwardAppBar({
required this.isSearchBarShowNotifier,
this.sendFromRoomId,
required this.textEditingController,
});

final String? sendFromRoomId;

final ValueNotifier<bool> isSearchBarShowNotifier;

final TextEditingController textEditingController;

@override
Widget build(BuildContext context) {
return AppBar(
Expand Down Expand Up @@ -181,6 +186,7 @@ class _ForwardAppBar extends StatelessWidget {
padding: const EdgeInsets.only(top: 8.0),
child: TextField(
autofocus: true,
controller: textEditingController,
maxLines: 1,
buildCounter: (
BuildContext context, {
Expand Down

0 comments on commit 7d82710

Please sign in to comment.