Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for spaces by term #81

Merged
merged 18 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions example/demo_app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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`)
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion example/demo_app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions example/demo_app/lib/views/spaces/__spaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export 'popular/popular_space_provider.dart';
export 'popular/popular_tab.dart';

export 'your_spaces/for_you_tab.dart';
export 'search_spaces.screen.dart';
74 changes: 72 additions & 2 deletions example/demo_app/lib/views/spaces/search_spaces.screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../../__lib.dart';
import 'package:push_restapi_dart/push_restapi_dart.dart';

class SearchSpacesScreen extends StatefulWidget {
const SearchSpacesScreen({super.key});
Expand All @@ -9,14 +10,83 @@ class SearchSpacesScreen extends StatefulWidget {

class _SearchSpacesScreenState extends State<SearchSpacesScreen> {
TextEditingController controller = TextEditingController();

List<SpaceDTO> _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(
body: SafeArea(
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);
},
))
],
),
),
),
Expand Down
10 changes: 10 additions & 0 deletions example/demo_app/lib/views/spaces_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ class _SpacesTabState extends ConsumerState<SpacesTab> {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: () {
pushScreen(SearchSpacesScreen());
},
child: Icon(
Icons.search,
color: pushColor,
),
),
Spacer(),
InkWell(
onTap: () {
pushScreen(CreateSpaceScreen());
Expand Down
1 change: 1 addition & 0 deletions lib/src/spaces/space.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
26 changes: 26 additions & 0 deletions lib/src/spaces/src/search.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:push_restapi_dart/push_restapi_dart.dart';

Future<List<SpaceDTO>> 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;
}
}