Skip to content

Commit

Permalink
Working searchbar, friend list, party creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpiniasty committed Jul 8, 2023
1 parent e6df117 commit 53f946c
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 169 deletions.
11 changes: 6 additions & 5 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class PartyController {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final userId = await storage.read(key: "user_publicId");

final url = "$mainUrl/parties/requests/${party.publicId}/";
final res = await http.post(
Uri.parse(url),
Expand Down Expand Up @@ -56,6 +55,7 @@ class PartyController {
"Authorization": "Bearer $token",
},
);
if (res.statusCode != 200) return [];
final invitations = <PartyInvitation>[];
for (final pi in jsonDecode(res.body)["results"]) {
invitations.add(PartyInvitation.fromMap(pi));
Expand All @@ -68,20 +68,21 @@ class PartyController {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
//TODO add party participants
final res = await http.post(
Uri.parse(url),
body: {
"owner": {},
body: jsonEncode({
"owner": <String, String>{},
"owner_public_id": party.ownerPublicId,
"name": party.name,
"privacy_status": party.privacyStatus,
"description": party.description,
"location": party.location!.toPOINT(),
"start_time": party.startTime.toIso8601String(),
"stop_time": party.stopTime.toIso8601String(),
},
"participants": [for (final p in party.participants!) p.toMap()],
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
Expand Down
15 changes: 14 additions & 1 deletion lib/controllers/search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../models/party.dart';
///Used for searching parties and users
class SearchController {
///Retrieves user's data based on provided [username]
static Future<List<Friend>> searchUser(String username) async {
static Future<List<Friend>> searchUserByUsername(String username) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");

Expand All @@ -29,6 +29,19 @@ class SearchController {
return users;
}

static Future<Friend> searchUserByPublicId(String id) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/users/$id/";
final res = await http.get(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);
return Friend.fromMap(jsonDecode(res.body));
}

static Future<List<Party>> seachPartiesByDistance({
double meters = 1000,
required LatLng location,
Expand Down
11 changes: 11 additions & 0 deletions lib/models/friend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class Friend {
);
}

Map<String, dynamic> toMap() {
return {
"public_id": publicId,
"username": username,
"first_name": firstName,
"last_name": lastName,
"date_of_birth": dateOfBirth!.toYMD(),
"pfp": pfp,
};
}

@override
String toString() {
return "$username $firstName $lastName $dateOfBirth";
Expand Down
10 changes: 5 additions & 5 deletions lib/models/party.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import '/utils/ext.dart';
class Party {
final String? publicId;
final Friend? owner;
final String ownerPublicId;
final String? ownerPublicId;
final String name;
final int? privacyStatus;
final String? privacyStatusDisplay;
final String description;
final String? image;
final List<Friend>? participants;
final LatLng? location;
final String? distance;
final int? distance;
final DateTime startTime;
final DateTime stopTime;

const Party({
this.publicId,
this.owner,
required this.ownerPublicId,
this.ownerPublicId,
required this.name,
this.privacyStatus,
this.privacyStatusDisplay,
Expand All @@ -43,8 +43,8 @@ class Party {
description: m["description"],
startTime: DateTime.parse(m["start_time"] as String),
stopTime: DateTime.parse(m["stop_time"] as String),
distance: (m["distance"]),
location: (m["location"] as String).toLatLng(),
distance: m["distance"],
location: (m["location"] as String).toLatLngReceive(),
privacyStatus: m["privacy_status"],
privacyStatusDisplay: m["privacy_status_display"],
image: m["image"],
Expand Down
1 change: 1 addition & 0 deletions lib/routes/create_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
),
child: Column(
children: [
//TODO implement image picking
FormFieldParty(
index: 1,
caption: AppLocalizations.of(context)!.title,
Expand Down
1 change: 1 addition & 0 deletions lib/routes/create_party_routes/invite_friends_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class _InviteFriendsPageState extends State<InviteFriendsPage> {
),
child: TextField(
controller: searchCtrl,
cursorColor: Theming.primaryColor,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
Expand Down
113 changes: 74 additions & 39 deletions lib/routes/friend_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,96 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../widgets/partiespage/user_holder.dart';
import '../utils/theming.dart';
import '../models/friend.dart';
import '../controllers/user_controller.dart';

class FriendListPage extends StatelessWidget {
class FriendListPage extends StatefulWidget {
const FriendListPage({super.key});

@override
State<FriendListPage> createState() => _FriendListPageState();
}

class _FriendListPageState extends State<FriendListPage> {
late List<Friend> friends;

@override
void initState() {
super.initState();
friends = [];
WidgetsBinding.instance.addPostFrameCallback((_) async {
final user = await UserController.me();
if (!mounted) return;
setState(() => friends = user.friends!);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theming.bgColor,
appBar: AppBar(
backgroundColor: Theming.bgColor,
leading: Padding(
padding: const EdgeInsets.only(left: 20),
child: IconButton(
onPressed: () => context.pop(),
icon: const Icon(
Icons.arrow_back_ios_rounded,
color: Theming.whiteTone,
body: Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: Theming.bgColor,
pinned: true,
surfaceTintColor: Colors.transparent,
centerTitle: true,
title: Text(
AppLocalizations.of(context)!.friends,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
leading: GestureDetector(
onTap: () => context.pop(),
child: const Icon(Icons.arrow_back_ios_new_rounded),
),
),
friends.isEmpty ? const SliverToBoxAdapter() : _friendList(),
],
),
),
),
title: Text(
AppLocalizations.of(context)!.friends,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: Theming.bgColor,
expandedHeight: 200,
pinned: true,
surfaceTintColor: Colors.transparent,
leading: GestureDetector(
onTap: () => context.pop(),
child: const Icon(Icons.arrow_back_ios_new_rounded),
Center(
child: Text(
AppLocalizations.of(context)!.emptyHere,
style: TextStyle(
color: Theming.whiteTone.withOpacity(0.7),
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
for (int i = 0; i < 15; i++) _friendPlaceholder(),
],
),
),
],
),
);
}

Widget _friendPlaceholder() {
return const SliverToBoxAdapter(
child: SizedBox(
height: 100,
Widget _friendList() {
return SliverToBoxAdapter(
child: Column(
children: [
for (final f in friends)
UserHolder(
f,
onButtonTap: () => context.go("/profile", extra: f),
buttonChild: Text(
AppLocalizations.of(context)!.navbarProfile,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/routes/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _HomePageState extends State<HomePage> {
user = User.emptyUser();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final userData = await UserController.me();
if (!mounted) return;
setState(() => user = userData);
});
}
Expand Down
20 changes: 11 additions & 9 deletions lib/routes/parties_users_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ class _PartiesUsersPageState extends State<PartiesUsersPage> {
: _resultList<Friend>(users),
),
SearchAndMap(
onPartySearch: (parties) {
if (mounted) {
//...
}
onTypeChange: (t) {
setState(() => searchType = t);
},
onUserSearch: (users) {
if (mounted) {
//...
}
onPartySearch: (p) {
if (!mounted) return;
setState(() => parties = p);
},
onUserSearch: (u) {
if (!mounted) return;
setState(() => users = u);
},
),
],
Expand All @@ -91,7 +92,7 @@ class _PartiesUsersPageState extends State<PartiesUsersPage> {
children: [
const SizedBox(height: 130),
for (final i in iter)
T is Party
T == Party
? PartyHolder(i as Party)
: UserHolder(
i as Friend,
Expand All @@ -103,6 +104,7 @@ class _PartiesUsersPageState extends State<PartiesUsersPage> {
senderPublicId: userId,
),
);

if (success && mounted) {
showModalBottomSheet(
context: context,
Expand Down
Loading

0 comments on commit 53f946c

Please sign in to comment.