Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit d3bdc82

Browse files
author
nathanvandeperre97
authored
feat(share) : User can now see who shared the list (#313)
1 parent c3ce03d commit d3bdc82

File tree

10 files changed

+205
-79
lines changed

10 files changed

+205
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4040
- Add possiblity to add a recipe to a list
4141
- Add choose wishlist color
4242
- Add user can now save a picture
43+
- Add owner picture on shared list
4344
- Add invitation email on inexistent user
4445

4546
### Changed

lib/dao/wishlist_dao.dart

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:MobileOne/data/owner_details.dart';
12
import 'package:cloud_firestore/cloud_firestore.dart';
23
import 'package:flutter/material.dart';
34

@@ -11,7 +12,8 @@ class WishlistDao {
1112
Future<DocumentSnapshot> fetchShareLists(String userUuid) =>
1213
FirebaseFirestore.instance.collection("shared").doc(userUuid).get();
1314

14-
Future<void> addWishlist(String wishlistUuid, String userUuid) async {
15+
Future<void> addWishlist(
16+
String wishlistUuid, String userUuid, String userEmail) async {
1517
String wishlistName;
1618

1719
await FirebaseFirestore.instance
@@ -37,6 +39,8 @@ class WishlistDao {
3739
'itemCounts': "0",
3840
'label': wishlistName,
3941
'timestamp': new DateTime.now(),
42+
'owner': userUuid,
43+
'ownerEmail': userEmail,
4044
});
4145

4246
//Check if the user already have a wishlist
@@ -126,10 +130,13 @@ class WishlistDao {
126130
Future<DocumentSnapshot> fetchWishlist(String uuid) =>
127131
FirebaseFirestore.instance.collection("wishlists").doc(uuid).get();
128132

129-
changeWishlistLabel(String label, String listUuid) =>
133+
changeWishlistLabel(
134+
String label, String listUuid, String userUid, String userEmail) =>
130135
FirebaseFirestore.instance.collection("wishlists").doc(listUuid).set(
131136
{
132137
"label": label,
138+
"owner": userUid,
139+
"ownerEmail": userEmail,
133140
},
134141
SetOptions(merge: true),
135142
);
@@ -387,4 +394,41 @@ class WishlistDao {
387394
SetOptions(merge: true),
388395
);
389396
}
397+
398+
Future<OwnerDetails> getOwnerDetails(String listUuid) async {
399+
String ownerUid;
400+
String email;
401+
String path;
402+
403+
await FirebaseFirestore.instance
404+
.collection("wishlists")
405+
.doc(listUuid)
406+
.get()
407+
.then((value) {
408+
if (value != null && value.data() != null) {
409+
if (value.data()["owner"] != null) {
410+
ownerUid = value.data()["owner"];
411+
}
412+
if (value.data()["ownerEmail"] != null) {
413+
email = value.data()["ownerEmail"];
414+
}
415+
}
416+
});
417+
418+
if (ownerUid != null) {
419+
await FirebaseFirestore.instance
420+
.collection("userPicture")
421+
.doc(ownerUid)
422+
.get()
423+
.then((value) {
424+
if (value != null && value.data() != null) {
425+
if (value.data()["path"] != null) {
426+
path = value.data()["path"];
427+
}
428+
}
429+
});
430+
}
431+
432+
return OwnerDetails.fromMap(path, email);
433+
}
390434
}

lib/data/owner_details.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class OwnerDetails {
2+
String path;
3+
String email;
4+
5+
OwnerDetails.fromMap(String path, String email) {
6+
this.path = path;
7+
this.email = email;
8+
}
9+
}

lib/pages/lists.dart

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,9 @@ class ListsState extends State<Lists> {
243243
onTap: () {
244244
openOpenedListPage(lists[index], false);
245245
},
246-
child: Container(
247-
child: Padding(
248-
padding: const EdgeInsets.all(5.0),
249-
child: WidgetLists(
250-
listUuid: lists[index],
251-
),
252-
),
246+
child: Padding(
247+
padding: const EdgeInsets.all(5.0),
248+
child: WidgetLists(listUuid: lists[index], isGuest: false),
253249
));
254250
},
255251
),
@@ -276,27 +272,24 @@ class ListsState extends State<Lists> {
276272
if (guestList.isEmpty) {
277273
return emptyShare();
278274
} else {
279-
return Container(
280-
child: Padding(
281-
padding: const EdgeInsets.only(left: 8.0),
282-
child: Container(
283-
child: ListView.builder(
284-
scrollDirection: Axis.horizontal,
285-
itemCount: guestList.length,
286-
itemBuilder: (BuildContext ctxt, index) {
287-
return GestureDetector(
288-
onTap: () {
289-
openOpenedListPage(guestList[index], true);
290-
},
291-
child: Padding(
292-
padding: const EdgeInsets.all(5.0),
293-
child: WidgetLists(
294-
listUuid: guestList[index],
295-
),
296-
));
297-
},
298-
),
299-
),
275+
return Padding(
276+
padding: const EdgeInsets.only(left: 8.0),
277+
child: ListView.builder(
278+
scrollDirection: Axis.horizontal,
279+
itemCount: guestList.length,
280+
itemBuilder: (BuildContext ctxt, index) {
281+
return Container(
282+
child: GestureDetector(
283+
onTap: () {
284+
openOpenedListPage(guestList[index], true);
285+
},
286+
child: Padding(
287+
padding: const EdgeInsets.all(5.0),
288+
child:
289+
WidgetLists(listUuid: guestList[index], isGuest: true),
290+
)),
291+
);
292+
},
300293
),
301294
);
302295
}

lib/pages/openedListPage.dart

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -371,29 +371,38 @@ class OpenedListPageState extends State<OpenedListPage>
371371
AppBar buildAppBar(BuildContext context, Wishlist wishlistHead) {
372372
return AppBar(
373373
backgroundColor: _colorsApp.colorTheme,
374-
title: TextField(
375-
onTap: () => _myController.selection = TextSelection(
376-
baseOffset: 0, extentOffset: _myController.text.length),
377-
focusNode: _nameFocusNode,
378-
style: TextStyle(
379-
color: WHITE,
380-
),
381-
controller: _myController,
382-
textAlign: TextAlign.center,
383-
decoration: InputDecoration(
384-
hintText: getString(context, "wishlist_name"),
385-
hintStyle: TextStyle(color: _colorsApp.greyColor),
386-
enabledBorder: OutlineInputBorder(
387-
borderSide: BorderSide(color: TRANSPARENT),
388-
),
389-
filled: true,
390-
fillColor: Colors.transparent,
391-
),
392-
onSubmitted: (_) {
393-
_wishlistProvider.changeWishlistLabel(
394-
_myController.text, wishlistHead.uuid);
395-
},
396-
),
374+
title: _args.isGuest
375+
? Center(
376+
child: Text(
377+
_myController.text,
378+
style: TextStyle(
379+
color: WHITE,
380+
),
381+
),
382+
)
383+
: TextField(
384+
onTap: () => _myController.selection = TextSelection(
385+
baseOffset: 0, extentOffset: _myController.text.length),
386+
focusNode: _nameFocusNode,
387+
style: TextStyle(
388+
color: WHITE,
389+
),
390+
controller: _myController,
391+
textAlign: TextAlign.center,
392+
decoration: InputDecoration(
393+
hintText: getString(context, "wishlist_name"),
394+
hintStyle: TextStyle(color: _colorsApp.greyColor),
395+
enabledBorder: OutlineInputBorder(
396+
borderSide: BorderSide(color: TRANSPARENT),
397+
),
398+
filled: true,
399+
fillColor: Colors.transparent,
400+
),
401+
onSubmitted: (_) {
402+
_wishlistProvider.changeWishlistLabel(
403+
_myController.text, wishlistHead.uuid);
404+
},
405+
),
397406
actions: [
398407
FlatButton(
399408
onPressed: () {
@@ -430,11 +439,6 @@ class OpenedListPageState extends State<OpenedListPage>
430439
value: 3,
431440
child: Text(getString(context, 'leave_share')),
432441
),
433-
PopupMenuItem(
434-
key: Key("renameWishlist"),
435-
value: 5,
436-
child: Text(getString(context, 'rename')),
437-
),
438442
]
439443
: [
440444
PopupMenuItem(

lib/pages/share_two.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class ShareStateTwoState extends State<ShareTwo> {
128128
height: 100,
129129
child: WidgetLists(
130130
listUuid: wishlists[index].uuid,
131+
isGuest: false,
131132
),
132133
),
133134
),

lib/services/wishlist_service.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:MobileOne/dao/wishlist_dao.dart';
2+
import 'package:MobileOne/data/owner_details.dart';
23
import 'package:MobileOne/data/wishlist.dart';
34
import 'package:MobileOne/data/wishlist_item.dart';
45
import 'package:MobileOne/services/analytics_services.dart';
@@ -22,13 +23,15 @@ class WishlistService {
2223
Map<String, dynamic> _shareLists = {};
2324
Map<String, dynamic> _ownerLists = {};
2425
Map<String, dynamic> _guestLists = {};
26+
Map<String, OwnerDetails> _ownerDetails = {};
2527

2628
void _flush() {
2729
_wishlists = {};
2830
_itemlists = {};
2931
_shareLists = {};
3032
_ownerLists = {};
3133
_guestLists = {};
34+
_ownerDetails = {};
3235
}
3336

3437
List get ownerLists => _ownerLists[userService.user.uid];
@@ -77,8 +80,9 @@ class WishlistService {
7780

7881
addWishlist(BuildContext context) async {
7982
final wishlistUuid = Uuid().v4();
80-
await dao.addWishlist(wishlistUuid, userService.user.uid).whenComplete(() =>
81-
Navigator.of(context).pushNamed('/openedListPage',
83+
await dao
84+
.addWishlist(wishlistUuid, userService.user.uid, userService.user.email)
85+
.whenComplete(() => Navigator.of(context).pushNamed('/openedListPage',
8286
arguments:
8387
OpenedListArguments(listUuid: wishlistUuid, isGuest: false)));
8488
_flush();
@@ -109,7 +113,8 @@ class WishlistService {
109113

110114
changeWishlistLabel(String label, String listUuid) async {
111115
label == null ? label = "" : label = label;
112-
dao.changeWishlistLabel(label, listUuid);
116+
dao.changeWishlistLabel(
117+
label, listUuid, userService.user.uid, userService.user.email);
113118
_wishlists[listUuid].label = label;
114119
}
115120

@@ -263,4 +268,14 @@ class WishlistService {
263268
}
264269
await dao.setWishlistColor(wishlistUuid, color);
265270
}
271+
272+
Future<OwnerDetails> getOwnerDetails(String listUuid) async {
273+
if (_ownerDetails.containsKey(listUuid)) {
274+
return _ownerDetails[listUuid];
275+
} else {
276+
OwnerDetails ownerDetails = await dao.getOwnerDetails(listUuid);
277+
_ownerDetails.addAll({listUuid: ownerDetails});
278+
return _ownerDetails[listUuid];
279+
}
280+
}
266281
}

lib/utility/curvePainter.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ class CurvePainter extends CustomPainter {
4848
Paint paint = Paint();
4949

5050
path = Path();
51-
path.lineTo(0, size.height * 0.75);
52-
path.lineTo(size.height * 0.1, size.height * 0.7);
53-
path.lineTo(size.height * 0.15, size.height * 0.75);
54-
path.lineTo(size.height * 0.2, size.height * 0.7);
55-
path.lineTo(size.height * 0.25, size.height * 0.75);
56-
path.lineTo(size.height * 0.3, size.height * 0.7);
57-
path.lineTo(size.height * 0.35, size.height * 0.75);
58-
path.lineTo(size.height * 0.4, size.height * 0.7);
59-
path.lineTo(size.height * 0.45, size.height * 0.7);
60-
path.lineTo(size.height * 0.5, size.height * 0.75);
61-
path.lineTo(size.height * 0.55, size.height * 0.6);
62-
path.lineTo(size.height * 0.6, size.height * 0.7);
63-
path.lineTo(size.height * 0.65, size.height * 0.75);
64-
path.lineTo(size.height * 0.7, size.height * 0.7);
65-
path.lineTo(size.width, size.height * 0.75);
51+
path.lineTo(0, size.height * 0.85);
52+
path.lineTo(size.height * 0.1, size.height * 0.8);
53+
path.lineTo(size.height * 0.15, size.height * 0.85);
54+
path.lineTo(size.height * 0.2, size.height * 0.8);
55+
path.lineTo(size.height * 0.25, size.height * 0.85);
56+
path.lineTo(size.height * 0.3, size.height * 0.8);
57+
path.lineTo(size.height * 0.35, size.height * 0.85);
58+
path.lineTo(size.height * 0.4, size.height * 0.8);
59+
path.lineTo(size.height * 0.45, size.height * 0.8);
60+
path.lineTo(size.height * 0.5, size.height * 0.85);
61+
path.lineTo(size.height * 0.55, size.height * 0.7);
62+
path.lineTo(size.height * 0.6, size.height * 0.8);
63+
path.lineTo(size.height * 0.65, size.height * 0.85);
64+
path.lineTo(size.height * 0.7, size.height * 0.8);
65+
path.lineTo(size.width, size.height * 0.85);
6666
path.lineTo(size.width, 0);
6767

6868
path.close();

0 commit comments

Comments
 (0)