From 234a17c22a3b171fe50df97278b6438c3460e63a Mon Sep 17 00:00:00 2001 From: gbogboadePush <135420608+gbogboadePush@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:13:48 +0100 Subject: [PATCH] Search for spaces by term (#81) * feat: add search by space name method * feat: add search space screen --------- Co-authored-by: Gbogboade Ayomide Co-authored-by: Madhur Gupta --- example/demo_app/ios/Podfile.lock | 31 ++++---- .../ios/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../demo_app/lib/views/spaces/__spaces.dart | 1 + .../views/spaces/search_spaces.screen.dart | 74 ++++++++++++++++++- example/demo_app/lib/views/spaces_tab.dart | 10 +++ lib/src/spaces/space.dart | 1 + lib/src/spaces/src/search.dart | 26 +++++++ 8 files changed, 128 insertions(+), 19 deletions(-) create mode 100644 lib/src/spaces/src/search.dart diff --git a/example/demo_app/ios/Podfile.lock b/example/demo_app/ios/Podfile.lock index a5e0ed1..ff43ff7 100644 --- a/example/demo_app/ios/Podfile.lock +++ b/example/demo_app/ios/Podfile.lock @@ -9,15 +9,15 @@ PODS: - Flutter - flutter_webrtc (0.9.36): - Flutter - - WebRTC-SDK (= 114.5735.02) + - WebRTC-SDK (= 114.5735.08) - image_cropper (0.0.4): - Flutter - TOCropViewController (~> 2.6.1) - image_picker_ios (0.0.1): - Flutter - - livekit_client (1.4.0): + - livekit_client (1.5.6): - Flutter - - WebRTC-SDK (= 114.5735.02) + - WebRTC-SDK (= 114.5735.08) - openpgp (0.6.0): - Flutter - path_provider_foundation (0.0.1): @@ -29,7 +29,8 @@ PODS: - TOCropViewController (2.6.1) - video_player_avfoundation (0.0.1): - Flutter - - WebRTC-SDK (114.5735.02) + - FlutterMacOS + - WebRTC-SDK (114.5735.08) DEPENDENCIES: - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) @@ -43,7 +44,7 @@ DEPENDENCIES: - openpgp (from `.symlinks/plugins/openpgp/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/ios`) + - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`) SPEC REPOS: trunk: @@ -75,24 +76,24 @@ EXTERNAL SOURCES: permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" video_player_avfoundation: - :path: ".symlinks/plugins/video_player_avfoundation/ios" + :path: ".symlinks/plugins/video_player_avfoundation/darwin" SPEC CHECKSUMS: - connectivity_plus: 07c49e96d7fc92bc9920617b83238c4d178b446a - device_info_plus: 7545d84d8d1b896cb16a4ff98c19f07ec4b298ea + connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d + device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6 Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_native_image: 9c0b7451838484458e5b0fae007b86a4c2d4bdfe - flutter_webrtc: 1944895d4e908c4bc722929dc4b9f8620d8e1b2f + flutter_webrtc: 55df3aaa802114dad390191a46c2c8d535751268 image_cropper: a3291c624a953049bc6a02e1f8c8ceb162a24b25 - image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5 - livekit_client: dedfd6601bfb2c567d6988491c8bab7ceeb5a6d9 - openpgp: 7d926bdb9e5544b1ae69a7a051716c36a3271b38 - path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 + image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425 + livekit_client: 381ed3cad6ba0b6ffbfffcf1b5db95ad1e61ffa2 + openpgp: 117b855c299b1e74f9f58fc027adf456aaac09c2 + path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863 - video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126 - WebRTC-SDK: dd913fd31cfbf1d43b9a22d83f4c6354c960c623 + video_player_avfoundation: e9e6f9cae7d7a6d9b43519b0aab382bca60fcfd1 + WebRTC-SDK: c24d2a6c9f571f2ed42297cb8ffba9557093142b PODFILE CHECKSUM: f9420bd595da8fbce156b547dcd3368afc5226ff diff --git a/example/demo_app/ios/Runner.xcodeproj/project.pbxproj b/example/demo_app/ios/Runner.xcodeproj/project.pbxproj index 8e89e93..ef6b253 100644 --- a/example/demo_app/ios/Runner.xcodeproj/project.pbxproj +++ b/example/demo_app/ios/Runner.xcodeproj/project.pbxproj @@ -214,7 +214,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { diff --git a/example/demo_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/demo_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e42adcb..87131a0 100644 --- a/example/demo_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/demo_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ { TextEditingController controller = TextEditingController(); + + List _spaces = []; + + bool isSearching = false; + + Future _searchSpace() async { + try { + final term = controller.text.trim(); + if (term.isEmpty) { + setState(() { + _spaces.clear(); + isSearching = false; + }); + + return; + } + setState(() { + isSearching = true; + }); + final result = await searchSpaces(searchTerm: term); + + setState(() { + _spaces = result; + isSearching = false; + }); + } catch (e) { + showErrorSnackbar(e.toString()); + } + } + @override Widget build(BuildContext context) { return Scaffold( @@ -16,7 +47,46 @@ class _SearchSpacesScreenState extends State { child: Padding( padding: EdgeInsets.all(16.0), child: Column( - children: [], + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + InkWell( + onTap: pop, + child: Icon( + Icons.close, + color: Colors.black, + ), + ), + SizedBox(height: 8), + SearchBar( + controller: controller, + hintText: 'enter space name', + trailing: [ + IconButton( + onPressed: isSearching + ? null + : () { + _searchSpace(); + }, + icon: Icon(Icons.search), + ) + ], + ), + SizedBox(height: 16), + Expanded( + child: isSearching + ? Center(child: LoadingDialog()) + : ListView.separated( + separatorBuilder: (context, index) => + SizedBox(height: 16), + itemCount: _spaces.length, + itemBuilder: (context, index) { + final item = SpaceFeeds( + spaceId: _spaces[index].spaceId, + spaceInformation: _spaces[index]); + return SpaceItemTile(item: item); + }, + )) + ], ), ), ), diff --git a/example/demo_app/lib/views/spaces_tab.dart b/example/demo_app/lib/views/spaces_tab.dart index 23076c3..9b4cb9d 100644 --- a/example/demo_app/lib/views/spaces_tab.dart +++ b/example/demo_app/lib/views/spaces_tab.dart @@ -18,6 +18,16 @@ class _SpacesTabState extends ConsumerState { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ + InkWell( + onTap: () { + pushScreen(SearchSpacesScreen()); + }, + child: Icon( + Icons.search, + color: pushColor, + ), + ), + Spacer(), InkWell( onTap: () { pushScreen(CreateSpaceScreen()); diff --git a/lib/src/spaces/space.dart b/lib/src/spaces/space.dart index 4ab275d..54eed84 100644 --- a/lib/src/spaces/space.dart +++ b/lib/src/spaces/space.dart @@ -9,6 +9,7 @@ export 'src/start.dart'; export 'src/update.dart'; export 'src/trending.dart'; export 'src/approve.dart'; +export 'src/search.dart'; export 'src/space.dart'; export 'src/request_to_be_promoted.dart'; diff --git a/lib/src/spaces/src/search.dart b/lib/src/spaces/src/search.dart new file mode 100644 index 0000000..3353e03 --- /dev/null +++ b/lib/src/spaces/src/search.dart @@ -0,0 +1,26 @@ +import 'package:push_restapi_dart/push_restapi_dart.dart'; + +Future> searchSpaces({ + required String searchTerm, + int pageNumber = 1, + int pageSize = 20, +}) async { + try { + final body = { + 'searchTerm': searchTerm, + 'pageNumber': pageNumber, + 'pageSize': pageSize, + }; + + final result = await http.post(path: '/v1/spaces/search', data: body); + + if (result == null || result is String) { + throw Exception(result ?? 'Cannot find spaces that match $searchTerm'); + } + + return (result as List).map((e) => SpaceDTO.fromJson(e)).toList(); + } catch (e) { + log('[Push SDK] - API - Error - API searchSpaces -: $e'); + rethrow; + } +}