Skip to content

Commit

Permalink
Sending friend request, fixed sending image while creating party, cod…
Browse files Browse the repository at this point in the history
…e refactoring
  • Loading branch information
jumpiniasty committed Jul 10, 2023
1 parent 4cd882d commit 439e94e
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 104 deletions.
1 change: 1 addition & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
untranslated-messages-file: untranslated.txt
49 changes: 30 additions & 19 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http_parser/http_parser.dart';

import '../utils/consts.dart';
import '../models/party.dart';
Expand Down Expand Up @@ -68,25 +70,34 @@ class PartyController {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
//TODO send image in HTTP request
final res = await http.post(
Uri.parse(url),
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",
},
);
final req = http.MultipartRequest("POST", Uri.parse(url));
req.fields.addAll(<String, String>{
"owner_public_id": party.ownerPublicId!,
"name": party.name,
"privacy_status": party.privacyStatus.toString(),
"description": party.description,
"location": party.location!.toPOINT(),
"start_time": party.startTime.toIso8601String(),
"stop_time": party.stopTime.toIso8601String(),
"participants":
jsonEncode([for (final p in party.participants!) p.toMap()]),
});
req.headers.addAll({
"Content-Type": "multipart/form-data",
"Authorization": "Bearer $token",
});
if (party.image != null) {
req.files.add(
http.MultipartFile(
"image",
File(party.image!).readAsBytes().asStream(),
File(party.image!).lengthSync(),
filename: party.image!,
contentType: MediaType("image", "jpeg"),
),
);
}
final res = await req.send();
return res.statusCode == 201;
}
}
8 changes: 7 additions & 1 deletion lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ class UserController {
}

static Future<bool> sendFriendInvitation(FriendInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/friends/invitations/";
final res = await http.post(
Uri.parse(url),
body: {
body: jsonEncode({
"sender": {},
"receiver": {},
"receiver_public_id": inv.receiverPublicId,
"sender_public_id": inv.senderPublicId,
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);

Expand Down
16 changes: 8 additions & 8 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
"partiesProfile2": "Parties",

"notificationsNotifications": "Notifications",
"invitationFrom": "Invitation from",
"notificationFrom": "From",
"secondsAgo": "seconds ago",
"minutesAgo": "minutes ago",
"hoursAgo": "hours ago",
"markAsRead": "Mark as read",
"friendInvitations": "Friend invitations",
"partyInvitations": "Party invitations",
"joinRequests": "Join requests",

"settings": "Settings",
"editProfile": "Edit profile",
"organization": "Organization",
"language": "Language",
"privacy": "Privacy",
"logOut": "Log out",

"editProfilePage": "Edit profile",
Expand All @@ -59,13 +59,11 @@
"sureDeleteAccount": "Delete your account?",
"deleteAccount": "Delete my account",
"doNotDeleteAccount": "Don't delete my account",
"updatedSuccess": "Account updated successfully",
"updatedFailure": "Could not update profile",

"yourParties": "Your parties",

"chooseALanguage": "Choose a language",
"polish": "Polski",
"english": "English",

"privacyPolicy": "Privacy policy",

"doYouWantToLogOut": "Do you want to log out?",
Expand All @@ -78,6 +76,8 @@
"join": "Join",
"error": "Error!",
"mapError": "It seems like you don't have any maps installed on your device.",
"joinRequestSuccess": "Join request sent",
"joinRequestFailure": "Could not send join request",

"logIn": "Log in",
"fillFieldsBelow": "Fill the fields below to continue.",
Expand Down
16 changes: 8 additions & 8 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
"partiesProfile2": "Imprezy",

"notificationsNotifications": "Powiadomienia",
"invitationFrom": "Zaproszenie od",
"notificationFrom": "Od",
"secondsAgo": "sekund temu",
"minutesAgo": "minut temu",
"hoursAgo": "godzin temu",
"markAsRead": "Oznacz jako przeczytane",
"friendInvitations": "Zaproszenia do znajomych",
"partyInvitations": "Zaproszenia na imprezę",
"joinRequests": "Prośby o dołączenie",

"settings": "Ustawienia",
"editProfile": "Edytuj profil",
"organization": "Organizacja",
"language": "Język",
"privacy": "Prywatność",
"logOut": "Wyloguj się",

"editProfilePage": "Edytuj profil",
Expand All @@ -59,13 +59,11 @@
"sureDeleteAccount": "Napewno chcesz usunąć konto?",
"deleteAccount": "Usuń moje konto",
"doNotDeleteAccount": "Nie usuwaj konta",
"updatedSuccess": "Pomyślnie zaaktualizowano profil",
"updatedFailure": "Nie zaaktualizowano profilu ",

"yourParties": "Twoje imprezy",

"chooseALanguage": "Wybierz język",
"polish": "Polski",
"english": "English",

"privacyPolicy": "Polityka prywatności",

"doYouWantToLogOut": "Wylogować cię?",
Expand All @@ -78,6 +76,8 @@
"join": "Dołącz",
"error": "Błąd!",
"mapError": "Wygląda na to, że nie masz zainstalowanych map na swoim urzadzeniu.",
"joinRequestSuccess": "Wysłano prośbę o dołączenie",
"joinRequestFailure": "Nie wysłano prośby",

"logIn": "Zaloguj się",
"fillFieldsBelow": "Wypełnij poniższe pola, aby kontynuować.",
Expand Down
34 changes: 11 additions & 23 deletions lib/routes/create_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,17 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
image: thumbnail?.path,
),
);
if (isCreated && mounted) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Theming.bgColor,
builder: (_) => SuccessSheet(
success: true,
successMsg: AppLocalizations.of(context)!.createdSuccessfuly,
failureMsg: AppLocalizations.of(context)!.creationFailed,
),
);
} else {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Theming.bgColor,
builder: (_) => SuccessSheet(
success: false,
successMsg: AppLocalizations.of(context)!.createdSuccessfuly,
failureMsg: AppLocalizations.of(context)!.creationFailed,
),
);
}
if (!mounted) return;
showModalBottomSheet(
context: context,
isScrollControlled: isCreated,
backgroundColor: Theming.bgColor,
builder: (_) => SuccessSheet(
success: false,
successMsg: AppLocalizations.of(context)!.createdSuccessfuly,
failureMsg: AppLocalizations.of(context)!.creationFailed,
),
);
},
),
),
Expand Down
45 changes: 24 additions & 21 deletions lib/routes/notifications_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../utils/theming.dart';
import '../widgets/dialogs/notification_sheet.dart';
import '../widgets/custom_floating_button.dart';
import '../widgets/dialogs/invitation_sheet.dart';
import '../controllers/party_creator_controller.dart';
import '../controllers/user_controller.dart';
import '../models/friend_invitiation.dart';
import '../models/party_invitation.dart';
import '../models/party_request.dart';
import '../widgets/notificationspage/category_row.dart';

class NotificationsPage extends StatefulWidget {
const NotificationsPage({super.key});
Expand All @@ -18,14 +18,22 @@ class NotificationsPage extends StatefulWidget {
State<NotificationsPage> createState() => _NotificationsPageState();
}

class _NotificationsPageState extends State<NotificationsPage> {
class _NotificationsPageState extends State<NotificationsPage>
with SingleTickerProviderStateMixin {
late final TabController _tabCtrl;

late List<FriendInvitation> friendInvs;
late List<PartyInvitation> partyInvs;
late List<PartyRequest> partyReqs;

@override
void initState() {
super.initState();
_tabCtrl = TabController(
length: 3,
vsync: this,
initialIndex: 0,
);
friendInvs = [];
partyInvs = [];
partyReqs = [];
Expand All @@ -36,20 +44,22 @@ class _NotificationsPageState extends State<NotificationsPage> {
});
}

@override
void dispose() {
super.dispose();
_tabCtrl.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theming.bgColor,
floatingActionButton: CustomFloatingButton(
caption: AppLocalizations.of(context)!.markAsRead,
onTap: () {},
),
body: CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: Theming.bgColor,
surfaceTintColor: Theming.bgColor,
expandedHeight: 115,
expandedHeight: 150,
pinned: true,
centerTitle: true,
shadowColor: Theming.bgColor,
Expand All @@ -72,16 +82,9 @@ class _NotificationsPageState extends State<NotificationsPage> {
),
),
),
flexibleSpace: const FlexibleSpaceBar(
centerTitle: true,
title: Text(
"5 notifications",
style: TextStyle(
color: Theming.primaryColor,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(54),
child: CategoryRow(_tabCtrl),
),
),
SliverList(
Expand All @@ -100,12 +103,12 @@ class _NotificationsPageState extends State<NotificationsPage> {
);
}

Widget _notificationItem(BuildContext ctx) {
Widget _notificationItem(/*Friend friend, */ BuildContext ctx) {
return InkWell(
onTap: () {
showModalBottomSheet(
context: ctx,
builder: (_) => const NotificationSheet(),
builder: (_) => const InvitationSheet(),
);
},
splashColor: Theming.whiteTone.withOpacity(0.05),
Expand Down Expand Up @@ -162,7 +165,7 @@ class _NotificationsPageState extends State<NotificationsPage> {
text: TextSpan(
children: [
TextSpan(
text: AppLocalizations.of(ctx)!.invitationFrom,
text: AppLocalizations.of(ctx)!.notificationFrom,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
Expand Down
17 changes: 15 additions & 2 deletions lib/routes/selected_party_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:drinkify/controllers/party_controller.dart';
import 'package:drinkify/widgets/dialogs/success_sheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
Expand Down Expand Up @@ -79,9 +81,20 @@ class _SelectedPartyPage extends State<SelectedPartyPage> {
floatingActionButton: Padding(
padding: const EdgeInsets.only(right: 14, bottom: 25),
child: GestureDetector(
onTap: () {
onTap: () async {
if (!showMore) return;
//TODO implement joining party
final success = await PartyController.sendJoinRequest(widget.party);
if (!mounted) return;
showModalBottomSheet(
context: context,
builder: (ctx) {
return SuccessSheet(
success: success,
successMsg: AppLocalizations.of(context)!.joinRequestSuccess,
failureMsg: AppLocalizations.of(context)!.joinRequestFailure,
);
},
);
},
child: GlassMorphism(
blur: showMore ? 10 : 0,
Expand Down
Loading

0 comments on commit 439e94e

Please sign in to comment.