diff --git a/app/lib/pages/conversations/widgets/search_widget.dart b/app/lib/pages/conversations/widgets/search_widget.dart index ed85fe2fc..9243ccb93 100644 --- a/app/lib/pages/conversations/widgets/search_widget.dart +++ b/app/lib/pages/conversations/widgets/search_widget.dart @@ -28,51 +28,69 @@ class _SearchWidgetState extends State { Widget build(BuildContext context) { return Container( padding: const EdgeInsets.fromLTRB(16, 0, 16, 0), - child: TextFormField( - controller: searchController, - focusNode: context.read().convoSearchFieldFocusNode, - onChanged: (value) { - var provider = Provider.of(context, listen: false); - _debouncer.run(() async { - await provider.searchConversations(value); - }); - setShowClearButton(); - }, - decoration: InputDecoration( - hintText: 'Search Conversations', - hintStyle: const TextStyle(color: Colors.white60, fontSize: 14), - filled: true, - fillColor: Colors.grey.shade900, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: TextFormField( + controller: searchController, + focusNode: context.read().convoSearchFieldFocusNode, + onChanged: (value) { + var provider = Provider.of(context, listen: false); + _debouncer.run(() async { + await provider.searchConversations(value); + }); + setShowClearButton(); + }, + decoration: InputDecoration( + hintText: 'Search Conversations', + hintStyle: const TextStyle(color: Colors.white60, fontSize: 14), + filled: true, + fillColor: Colors.grey.shade900, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(16), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(16), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(16), + ), + prefixIcon: const Icon( + Icons.search, + color: Colors.white60, + ), + suffixIcon: showClearButton + ? GestureDetector( + onTap: () async { + var provider = Provider.of(context, listen: false); + await provider.searchConversations(""); // clear + searchController.clear(); + setShowClearButton(); + }, + child: const Icon( + Icons.close, + color: Colors.white, + ), + ) + : null, + contentPadding: const EdgeInsets.symmetric(horizontal: 12), + ), + style: const TextStyle(color: Colors.white), + ), ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), - ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), - ), - prefixIcon: const Icon( - Icons.search, - color: Colors.white60, - ), - suffixIcon: showClearButton - ? GestureDetector( - onTap: () async { - var provider = Provider.of(context, listen: false); - await provider.searchConversations(""); // clear - searchController.clear(); - setShowClearButton(); - }, - child: const Icon( - Icons.close, - color: Colors.white, - ), - ) - : null, - contentPadding: const EdgeInsets.symmetric(horizontal: 12), - ), - style: const TextStyle(color: Colors.white), + Consumer( + builder: (BuildContext context, ConversationProvider convoProvider, Widget? child) { + return IconButton( + onPressed: convoProvider.toggleDiscardConversations, + icon: Icon( + convoProvider.showDiscardedConversations ? Icons.filter_list_off_sharp : Icons.filter_list, + color: Colors.white, + size: 24, + ), + ); + }), + ], ), ); } diff --git a/app/lib/providers/conversation_provider.dart b/app/lib/providers/conversation_provider.dart index 8cc2b1ecb..ddea0f159 100644 --- a/app/lib/providers/conversation_provider.dart +++ b/app/lib/providers/conversation_provider.dart @@ -14,7 +14,7 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener Map> groupedConversations = {}; bool isLoadingConversations = false; - bool hasNonDiscardedConversations = true; + bool showDiscardedConversations = false; String previousQuery = ''; int totalSearchPages = 1; @@ -75,8 +75,9 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener previousQuery = ""; currentSearchPage = 0; totalSearchPages = 0; - searchedConversations = conversations; - groupSearchConvosByDate(); + searchedConversations = []; + groupConversationsByDate(); + notifyListeners(); return; } @@ -148,6 +149,18 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener } } + void toggleDiscardConversations() { + showDiscardedConversations = !showDiscardedConversations; + + if (previousQuery.isNotEmpty) { + groupSearchConvosByDate(); + return; + } + groupConversationsByDate(); + + MixpanelManager().showDiscardedMemoriesToggled(showDiscardedConversations); + } + void setLoadingConversations(bool value) { isLoadingConversations = value; notifyListeners(); @@ -171,9 +184,25 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener notifyListeners(); } + List _filterOutConvos(List convos) { + var havingFilters = true; + if (showDiscardedConversations) { + havingFilters = false; + } + if (!havingFilters) { + return convos; + } + return convos.where((convo) { + if (!showDiscardedConversations && (convo.discarded && !convo.isNew)) { + return false; + } + return true; + }).toList(); + } + void _groupSearchConvosByDateWithoutNotify() { groupedConversations = {}; - for (var conversation in searchedConversations) { + for (var conversation in _filterOutConvos(searchedConversations)) { var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day); if (!groupedConversations.containsKey(date)) { groupedConversations[date] = []; @@ -189,7 +218,7 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener void _groupConversationsByDateWithoutNotify() { groupedConversations = {}; - for (var conversation in conversations) { + for (var conversation in _filterOutConvos(conversations)) { var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day); if (!groupedConversations.containsKey(date)) { groupedConversations[date] = [];