diff --git a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart index 98717ff..fbc25d9 100644 --- a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart +++ b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart @@ -23,6 +23,7 @@ class TopNavBarComponent extends StatefulWidget { class _TopNavBarComponentState extends State with TickerProviderStateMixin { bool choice = true; late AnimationController _controller; + bool isDismissed = true; final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1); @@ -31,11 +32,6 @@ class _TopNavBarComponentState extends State with TickerProv MyApp.postViewModel.getBestPosts(); } - void checkAvailable() async { - var res = await MyApp.postViewModel.getAvailable(); - showCapsuleDot(res); - } - @override void initState() { _controller = AnimationController( @@ -112,9 +108,21 @@ class _TopNavBarComponentState extends State with TickerProv ).show(context); } + void checkAvailable() async { + print("test"); + var res = await MyApp.postViewModel.getAvailable(); + print(res); + ModalRoute? route = ModalRoute.of(context); + if (route != null) { + if (route.settings.name != '/flushbarRoute') { + print("yes"); + showCapsuleDot(res); + } + } + } + @override Widget build(BuildContext context) { - checkAvailable(); return Padding( padding: const EdgeInsets.only(top: defaultPadding), child: Container( @@ -129,8 +137,11 @@ class _TopNavBarComponentState extends State with TickerProv flex: 1, child: GestureDetector( behavior: HitTestBehavior.translucent, - onTap: () { - Navigator.of(context).push(routeAddFriend()); + onTap: () async { + bool returnFromOtherPage = await Navigator.of(context).push(routeAddFriend()); + if (returnFromOtherPage == true) { + checkAvailable(); + } }, child: const Icon( Icons.person_add_alt_1_rounded, @@ -225,8 +236,11 @@ class _TopNavBarComponentState extends State with TickerProv Flexible( flex: 1, child: GestureDetector( - onTap: () { - Navigator.of(context).push(routeProfile()); + onTap: () async { + bool returnFromOtherPage = await Navigator.of(context).push(routeProfile()); + if (returnFromOtherPage == true) { + checkAvailable(); + } }, child: ClipOval( child: SizedBox.fromSize( diff --git a/Sources/justMUSIC/lib/screens/add_friend_screen.dart b/Sources/justMUSIC/lib/screens/add_friend_screen.dart index b4024df..298caf6 100644 --- a/Sources/justMUSIC/lib/screens/add_friend_screen.dart +++ b/Sources/justMUSIC/lib/screens/add_friend_screen.dart @@ -169,7 +169,7 @@ class _AddFriendScreenState extends State { GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { - Navigator.pop(context); + Navigator.pop(context, true); }, child: Transform( alignment: Alignment.center, diff --git a/Sources/justMUSIC/lib/screens/profile_screen.dart b/Sources/justMUSIC/lib/screens/profile_screen.dart index e3ff26e..3fd339c 100644 --- a/Sources/justMUSIC/lib/screens/profile_screen.dart +++ b/Sources/justMUSIC/lib/screens/profile_screen.dart @@ -32,7 +32,7 @@ class _ProfileScreenState extends State { GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { - Navigator.pop(context); + Navigator.pop(context, true); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 10), diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart index b7f87d2..7b3e76a 100644 --- a/Sources/justMUSIC/lib/services/PostService.dart +++ b/Sources/justMUSIC/lib/services/PostService.dart @@ -2,14 +2,14 @@ import 'dart:convert'; import 'dart:io'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:intl/intl.dart'; import 'package:tuple/tuple.dart'; 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, @@ -45,14 +45,11 @@ class PostService { getPostsById(String id) {} - 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,16 +64,16 @@ class PostService { Future getAvailable(String idUser) async { DateTime today = DateTime.now(); - today = DateTime(today.year, today.month, today.day); - QuerySnapshot> response = await FirebaseFirestore - .instance - .collection("posts") - .where("user_id", isEqualTo: idUser) - .where("date", isGreaterThanOrEqualTo: today) - .where("date", isLessThan: today.add(Duration(days: 1))) - .get(); + QuerySnapshot> response = + await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get(); + + // Utiliser any() pour vérifier s'il y a au moins un document avec la date d'aujourd'hui + 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 response.docs.isNotEmpty; + return !isTodayAvailable; } }