Refactor ActivityCard UI and improve voting functionality
- Updated ActivityCard layout for better visual consistency and responsiveness. - Simplified the category badge and adjusted styles for better readability. - Enhanced the voting section with a progress bar and improved button designs. - Added a new method in Activity model to check if all trip participants approved an activity. - Improved error handling and validation in ActivityRepository for voting and fetching activities. - Implemented pagination in ActivityPlacesService for activity searches. - Removed outdated scripts for cleaning up duplicate images.
This commit is contained in:
@@ -37,16 +37,20 @@ class ActivityRepository {
|
||||
try {
|
||||
print('ActivityRepository: Récupération des activités pour le voyage: $tripId');
|
||||
|
||||
// Modifié pour éviter l'erreur d'index composite
|
||||
// On récupère d'abord par tripId, puis on trie en mémoire
|
||||
final querySnapshot = await _firestore
|
||||
.collection(_collection)
|
||||
.where('tripId', isEqualTo: tripId)
|
||||
.orderBy('updatedAt', descending: true)
|
||||
.get();
|
||||
|
||||
final activities = querySnapshot.docs
|
||||
.map((doc) => Activity.fromSnapshot(doc))
|
||||
.toList();
|
||||
|
||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||
|
||||
print('ActivityRepository: ${activities.length} activités trouvées');
|
||||
return activities;
|
||||
} catch (e) {
|
||||
@@ -111,6 +115,19 @@ class ActivityRepository {
|
||||
/// Vote pour une activité
|
||||
Future<bool> voteForActivity(String activityId, String userId, int vote) async {
|
||||
try {
|
||||
// Validation des paramètres
|
||||
if (activityId.isEmpty) {
|
||||
print('ActivityRepository: ID d\'activité vide');
|
||||
_errorService.logError('activity_repository', 'ID d\'activité vide pour le vote');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userId.isEmpty) {
|
||||
print('ActivityRepository: ID d\'utilisateur vide');
|
||||
_errorService.logError('activity_repository', 'ID d\'utilisateur vide pour le vote');
|
||||
return false;
|
||||
}
|
||||
|
||||
print('ActivityRepository: Vote pour l\'activité $activityId: $vote');
|
||||
|
||||
// vote: 1 pour positif, -1 pour négatif, 0 pour supprimer le vote
|
||||
@@ -155,12 +172,16 @@ class ActivityRepository {
|
||||
return _firestore
|
||||
.collection(_collection)
|
||||
.where('tripId', isEqualTo: tripId)
|
||||
.orderBy('updatedAt', descending: true)
|
||||
.snapshots()
|
||||
.map((snapshot) {
|
||||
return snapshot.docs
|
||||
final activities = snapshot.docs
|
||||
.map((doc) => Activity.fromSnapshot(doc))
|
||||
.toList();
|
||||
|
||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||
|
||||
return activities;
|
||||
});
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur stream activités: $e');
|
||||
@@ -198,16 +219,23 @@ class ActivityRepository {
|
||||
/// Recherche des activités par catégorie
|
||||
Future<List<Activity>> getActivitiesByCategory(String tripId, String category) async {
|
||||
try {
|
||||
print('ActivityRepository: Recherche par catégorie: $category pour le voyage: $tripId');
|
||||
|
||||
// Récupérer toutes les activités du voyage puis filtrer en mémoire
|
||||
final querySnapshot = await _firestore
|
||||
.collection(_collection)
|
||||
.where('tripId', isEqualTo: tripId)
|
||||
.where('category', isEqualTo: category)
|
||||
.orderBy('updatedAt', descending: true)
|
||||
.get();
|
||||
|
||||
return querySnapshot.docs
|
||||
final activities = querySnapshot.docs
|
||||
.map((doc) => Activity.fromSnapshot(doc))
|
||||
.where((activity) => activity.category == category)
|
||||
.toList();
|
||||
|
||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||
|
||||
return activities;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur recherche par catégorie: $e');
|
||||
_errorService.logError('activity_repository', 'Erreur recherche par catégorie: $e');
|
||||
|
||||
Reference in New Issue
Block a user