diff --git a/Sources/justMUSIC/lib/components/recap_component.dart b/Sources/justMUSIC/lib/components/recap_component.dart index 925734f..d7ce67e 100644 --- a/Sources/justMUSIC/lib/components/recap_component.dart +++ b/Sources/justMUSIC/lib/components/recap_component.dart @@ -1,12 +1,18 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/Material.dart'; import 'package:google_fonts/google_fonts.dart'; - +import '../main.dart'; +import '../model/User.dart' as justMusic; import '../values/constants.dart'; import 'little_post_recap_component.dart'; -import 'package:intl/intl.dart'; class RecapComponent extends StatelessWidget { - const RecapComponent({super.key}); + final justMusic.User user; + const RecapComponent({super.key, required this.user}); + + Future>? _fetchdata() async { + return await MyApp.postViewModel.recapSevenDays(user.id); + } @override Widget build(BuildContext context) { @@ -85,25 +91,33 @@ class RecapComponent extends StatelessWidget { ], ), )), - Padding( - padding: EdgeInsets.all(12), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - LittleCapsule( - isEmpty: false, - date: DateTime.now(), - ), - LittleCapsule(isEmpty: true, date: currentDate.subtract(const Duration(days: 5))), - LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 4))), - LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 3))), - LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 2))), - LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 1))), - LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 0))), - ], - ), - ) + FutureBuilder>( + future: _fetchdata(), // a previously-obtained Future or null + builder: (BuildContext context, AsyncSnapshot> snapshot) { + if (snapshot.hasData) { + return Padding( + padding: EdgeInsets.all(12), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + LittleCapsule( + isEmpty: snapshot.data![0], + date: currentDate.subtract(const Duration(days: 6)), + ), + LittleCapsule(isEmpty: snapshot.data![1], date: currentDate.subtract(const Duration(days: 5))), + LittleCapsule(isEmpty: snapshot.data![2], date: currentDate.subtract(const Duration(days: 4))), + LittleCapsule(isEmpty: snapshot.data![3], date: currentDate.subtract(const Duration(days: 3))), + LittleCapsule(isEmpty: snapshot.data![4], date: currentDate.subtract(const Duration(days: 2))), + LittleCapsule(isEmpty: snapshot.data![5], date: currentDate.subtract(const Duration(days: 1))), + LittleCapsule(isEmpty: snapshot.data![6], date: currentDate.subtract(const Duration(days: 0))), + ], + ), + ); + } else { + return Container(); + } + }), ], ), ); diff --git a/Sources/justMUSIC/lib/components/setting_part_component.dart b/Sources/justMUSIC/lib/components/setting_part_component.dart index 21e47f1..3079d48 100644 --- a/Sources/justMUSIC/lib/components/setting_part_component.dart +++ b/Sources/justMUSIC/lib/components/setting_part_component.dart @@ -9,7 +9,9 @@ class SettingPartComponent extends StatelessWidget { final JustMusicIcon icon; final String label; final bool important; - const SettingPartComponent({Key? key, required this.icon, required this.label, this.important = false}) + final VoidCallback? action; + const SettingPartComponent( + {Key? key, required this.icon, required this.label, this.important = false, required this.action}) : super(key: key); @override @@ -24,11 +26,7 @@ class SettingPartComponent extends StatelessWidget { color: important ? warningBttnColor : settingColor, borderOnForeground: false, child: InkWell( - onTap: () { - if (icon == JustMusicIcon.cross) { - logout(); - } - }, + onTap: action, splashColor: Colors.transparent, highlightColor: Colors.white.withOpacity(0.08), child: Container( diff --git a/Sources/justMUSIC/lib/screens/profile_screen.dart b/Sources/justMUSIC/lib/screens/profile_screen.dart index 5d13b0c..a40fd0a 100644 --- a/Sources/justMUSIC/lib/screens/profile_screen.dart +++ b/Sources/justMUSIC/lib/screens/profile_screen.dart @@ -1,3 +1,4 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -5,6 +6,7 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:justmusic/values/icons.dart'; import '../components/profile_component.dart'; import '../components/setting_part_component.dart'; +import '../config/routes.dart'; import '../main.dart'; import '../values/constants.dart'; @@ -18,6 +20,16 @@ class ProfileScreen extends StatefulWidget { class _ProfileScreenState extends State { @override Widget build(BuildContext context) { + Future logout() async { + print("cc"); + await FirebaseAuth.instance.signOut(); + Navigator.pushNamed(context, '/welcome'); + } + + void _openDetail() { + Navigator.of(context).push(routeUser(MyApp.userViewModel.userCurrent)); + } + return Scaffold( appBar: PreferredSize( preferredSize: Size(double.infinity, 58), @@ -84,23 +96,28 @@ class _ProfileScreenState extends State { SettingPartComponent( icon: JustMusicIcon.profile, label: 'Compte', + action: _openDetail, ), - SettingPartComponent( + const SettingPartComponent( icon: JustMusicIcon.history, label: 'Historiques des capsules', + action: null, ), - SettingPartComponent( + const SettingPartComponent( icon: JustMusicIcon.spotify, label: 'Lier un compte Spotify', + action: null, ), - SettingPartComponent( + const SettingPartComponent( icon: JustMusicIcon.trash, label: 'Supprimer mon compte', + action: null, ), SettingPartComponent( icon: JustMusicIcon.cross, label: 'Déconnexion', important: true, + action: logout, ), ], ), @@ -114,15 +131,17 @@ class _ProfileScreenState extends State { ), ClipRRect( borderRadius: BorderRadius.circular(8), - child: Column( - children: const [ + child: const Column( + children: [ SettingPartComponent( icon: JustMusicIcon.theme, label: 'Thême de l\'application', + action: null, ), SettingPartComponent( icon: JustMusicIcon.notification, label: 'Notifications', + action: null, ), ], ), diff --git a/Sources/justMUSIC/lib/screens/user_screen.dart b/Sources/justMUSIC/lib/screens/user_screen.dart index 20e5855..c81851d 100644 --- a/Sources/justMUSIC/lib/screens/user_screen.dart +++ b/Sources/justMUSIC/lib/screens/user_screen.dart @@ -73,78 +73,80 @@ class _UserScreenState extends State { padding: EdgeInsets.only(top: 68.h, bottom: 40), child: ProfileComponent(user: widget.user), ), - Align( - alignment: Alignment.topCenter, - child: isClicked - ? SizedBox( - // Définir une largeur minimale pour le bouton "Ajouter" - width: 120, // Réglez cette valeur en fonction de vos besoins - child: Material( - borderRadius: BorderRadius.all(Radius.circular(5)), - color: selectedButton, - child: InkWell( - splashColor: Colors.white.withOpacity(0.3), - onTap: () async { - await MyApp.userViewModel.addOrDeleteFriend(widget.user.id); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - "Vous ne suivez plus ${widget.user.pseudo}", - style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h), - ), - backgroundColor: Colors.red, - closeIconColor: Colors.white, - ), - ); - setState(() {}); - }, - child: Container( - padding: EdgeInsets.fromLTRB(28, 7, 28, 7), - decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))), - child: Center( - child: Text("Ajouté", - style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)), - ), - ))), - ) - : SizedBox( - // Définir une largeur minimale pour le bouton "Ajouter" - width: 120, // Réglez cette valeur en fonction de vos besoins - child: Material( - borderRadius: BorderRadius.all(Radius.circular(5)), - color: primaryColor, - child: InkWell( - splashColor: Colors.white.withOpacity(0.3), - onTap: () async { - await MyApp.userViewModel.addOrDeleteFriend(widget.user.id); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - backgroundColor: primaryColor, - content: Text( - "Vous suivez à present ${widget.user.pseudo}", - style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h), - ), - ), - ); - setState(() {}); - }, - child: Container( - padding: EdgeInsets.fromLTRB(25, 7, 25, 7), - decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))), - child: Center( - child: Text("Ajouter", - style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)), - ), - )))), - ), + MyApp.userViewModel.userCurrent.id != widget.user.id + ? Align( + alignment: Alignment.topCenter, + child: isClicked + ? SizedBox( + // Définir une largeur minimale pour le bouton "Ajouter" + width: 120, // Réglez cette valeur en fonction de vos besoins + child: Material( + borderRadius: BorderRadius.all(Radius.circular(5)), + color: selectedButton, + child: InkWell( + splashColor: Colors.white.withOpacity(0.3), + onTap: () async { + await MyApp.userViewModel.addOrDeleteFriend(widget.user.id); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + "Vous ne suivez plus ${widget.user.pseudo}", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h), + ), + backgroundColor: Colors.red, + closeIconColor: Colors.white, + ), + ); + setState(() {}); + }, + child: Container( + padding: EdgeInsets.fromLTRB(28, 7, 28, 7), + decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))), + child: Center( + child: Text("Ajouté", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)), + ), + ))), + ) + : SizedBox( + // Définir une largeur minimale pour le bouton "Ajouter" + width: 120, // Réglez cette valeur en fonction de vos besoins + child: Material( + borderRadius: BorderRadius.all(Radius.circular(5)), + color: primaryColor, + child: InkWell( + splashColor: Colors.white.withOpacity(0.3), + onTap: () async { + await MyApp.userViewModel.addOrDeleteFriend(widget.user.id); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: primaryColor, + content: Text( + "Vous suivez à present ${widget.user.pseudo}", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h), + ), + ), + ); + setState(() {}); + }, + child: Container( + padding: EdgeInsets.fromLTRB(25, 7, 25, 7), + decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))), + child: Center( + child: Text("Ajouter", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)), + ), + )))), + ) + : Container(), SizedBox( height: 40, ), - RecapComponent() + RecapComponent(user: widget.user) ], ), ), diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart index 18719ab..17e2645 100644 --- a/Sources/justMUSIC/lib/services/PostService.dart +++ b/Sources/justMUSIC/lib/services/PostService.dart @@ -7,8 +7,7 @@ import 'package:firebase_storage/firebase_storage.dart'; import '../main.dart'; class PostService { - createPost(String? description, String idMusic, File? image, - Tuple2? location) async { + createPost(String? description, String idMusic, File? image, Tuple2? location) async { var id = MyApp.userViewModel.userCurrent.id; final post = { "user_id": id, @@ -42,14 +41,11 @@ class PostService { deletePost() {} - Future>>> getPopularPosts( - {int limit = 10, int offset = 0}) async { + Future>>> getPopularPosts({int limit = 10, int offset = 0}) async { DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24)); - Timestamp twentyFourHoursAgoTimestamp = - Timestamp.fromDate(twentyFourHoursAgo); + Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo); - QuerySnapshot> response = await FirebaseFirestore - .instance + QuerySnapshot> response = await FirebaseFirestore.instance .collection("posts") .where("date", isGreaterThan: twentyFourHoursAgoTimestamp) .limit(limit) @@ -67,8 +63,7 @@ class PostService { return Timestamp.fromDate(twentyFourHoursAgo); } - Future>>> getPostsFriends( - {int limit = 10, int offset = 0}) async { + Future>>> getPostsFriends({int limit = 10, int offset = 0}) async { var timestamp = _getTwentyFourHoursAgoTimestamp(); var response = await FirebaseFirestore.instance .collection("posts") @@ -84,17 +79,12 @@ class PostService { Future getAvailable(String idUser) async { DateTime today = DateTime.now(); - QuerySnapshot> response = await FirebaseFirestore - .instance - .collection("posts") - .where("user_id", isEqualTo: idUser) - .get(); + QuerySnapshot> response = + await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get(); bool isTodayAvailable = response.docs.any((doc) { DateTime date = doc["date"].toDate(); // Assuming the field name is "date" - return date.day == today.day && - date.month == today.month && - date.year == today.year; + return date.day == today.day && date.month == today.month && date.year == today.year; }); return !isTodayAvailable; @@ -103,17 +93,13 @@ class PostService { Future> recapSevenDays(String id) async { List recapList = []; - DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 7)); + DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 6)); - QuerySnapshot> response = await FirebaseFirestore - .instance - .collection("posts") - .where("user_id", isEqualTo: id) - .get(); + QuerySnapshot> response = + await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: id).get(); - List?> postList = response.docs - .map((DocumentSnapshot> doc) => doc.data()) - .toList(); + List?> postList = + response.docs.map((DocumentSnapshot> doc) => doc.data()).toList(); for (int i = 0; i < 7; i++) { DateTime date = sevenDaysAgo.add(Duration(days: i));