diff --git a/lib/components/account/account_content.dart b/lib/components/account/account_content.dart index 1abefc3..2cba932 100644 --- a/lib/components/account/account_content.dart +++ b/lib/components/account/account_content.dart @@ -28,8 +28,9 @@ import '../../blocs/account/account_state.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:travel_mate/components/error/error_content.dart'; import '../../blocs/user/user_state.dart' as user_state; -import '../../repositories/group_repository.dart'; // Ajouter cet import -import 'group_expenses_page.dart'; // Ajouter cet import +import '../../repositories/group_repository.dart'; +import '../widgets/user_state_widget.dart'; +import 'group_expenses_page.dart'; /// Widget that displays the account content page with account management functionality. class AccountContent extends StatefulWidget { @@ -132,33 +133,13 @@ class _AccountContentState extends State { /// Widget representing the complete account page UI @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, userState) { - if (userState is user_state.UserLoading) { - return const Scaffold( - body: Center(child: CircularProgressIndicator()), - ); - } - - if (userState is user_state.UserError) { - return ErrorContent( - message: 'User error: ${userState.message}', - onRetry: () {}, - ); - } - - if (userState is! user_state.UserLoaded) { - return const Scaffold( - body: Center(child: Text('User not connected')), - ); - } - final user = userState.user; - + return UserStateWrapper( + builder: (context, user) { return BlocConsumer( listener: (context, accountState) { if (accountState is AccountError) { ErrorContent( - message: 'Account loading error: ${accountState.message}', + message: 'Erreur de chargement des comptes : ${accountState.message}', onRetry: () { context.read().add(LoadAccountsByUserId(user.id)); }, @@ -167,11 +148,21 @@ class _AccountContentState extends State { }, builder: (context, accountState) { return Scaffold( - body: SafeArea(child: _buildContent(accountState, user.id)) - ); + body: SafeArea(child: _buildContent(accountState, user.id)), + ); }, ); - }, + }, + loadingWidget: const Scaffold( + body: Center(child: CircularProgressIndicator()), + ), + errorWidget: ErrorContent( + message: 'User error', + onRetry: () {}, + ), + noUserWidget: const Scaffold( + body: Center(child: Text('Utilisateur non connecté')), + ), ); } @@ -196,7 +187,7 @@ class _AccountContentState extends State { children: [ CircularProgressIndicator(), SizedBox(height: 16), - Text('Loading accounts...'), + Text('Chargement des comptes...'), ], ), ); @@ -204,7 +195,7 @@ class _AccountContentState extends State { if (accountState is AccountError) { return ErrorContent( - message: 'Account loading error...', + message: 'Erreur de chargement des comptes...', onRetry: () { context.read().add(LoadAccountsByUserId(userId)); }, @@ -222,13 +213,13 @@ class _AccountContentState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text('Unknown state'), + const Text('État inconnu'), const SizedBox(height: 16), ElevatedButton( onPressed: () { context.read().add(LoadAccountsByUserId(userId)); }, - child: const Text('Load accounts'), + child: const Text('Charger les comptes'), ), ], ), @@ -258,7 +249,7 @@ class _AccountContentState extends State { ), const SizedBox(height: 8), const Text( - 'Accounts are automatically created when you create a trip', + 'Les comptes sont créés automatiquement lorsque vous créez des voyages.', style: TextStyle(fontSize: 14, color: Colors.grey), textAlign: TextAlign.center, ), @@ -289,18 +280,7 @@ class _AccountContentState extends State { child: ListView( padding: const EdgeInsets.all(16), children: [ - const Text( - 'My accounts', - style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold), - ), - const SizedBox(height: 8), - Text( - 'Manage your travel accounts', - style: TextStyle(fontSize: 14, color: Colors.grey[600]), - ), - const SizedBox(height: 24), - - ...accounts.map((account) { + ...accounts.map((account) { return Padding( padding: const EdgeInsets.only(bottom: 12), child: _buildSimpleAccountCard(account), diff --git a/lib/components/group/chat_group_content.dart b/lib/components/group/chat_group_content.dart index ede4a62..1b2d5c0 100644 --- a/lib/components/group/chat_group_content.dart +++ b/lib/components/group/chat_group_content.dart @@ -476,8 +476,12 @@ class _ChatGroupContentState extends State { const SizedBox(height: 4), ], Text( - message.text, - style: TextStyle(fontSize: 15, color: textColor), + message.isDeleted ? 'a supprimé un message' : message.text, + style: TextStyle( + fontSize: 15, + color: message.isDeleted ? textColor.withValues(alpha: 0.5) : textColor, + fontStyle: message.isDeleted ? FontStyle.italic : FontStyle.normal, + ), ), const SizedBox(height: 4), Row( diff --git a/lib/components/group/group_content.dart b/lib/components/group/group_content.dart index e11d6d0..0f2253c 100644 --- a/lib/components/group/group_content.dart +++ b/lib/components/group/group_content.dart @@ -127,17 +127,6 @@ class _GroupContentState extends State { child: ListView( padding: const EdgeInsets.all(16), children: [ - const Text( - 'Mes groupes', - style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold), - ), - const SizedBox(height: 8), - Text( - 'Discutez avec les participants', - style: TextStyle(fontSize: 14, color: Colors.grey[600]), - ), - const SizedBox(height: 24), - ...groups.map((group) { return Padding( padding: const EdgeInsets.only(bottom: 12), diff --git a/lib/models/message.dart b/lib/models/message.dart index 4c3a099..e27ee58 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -10,6 +10,7 @@ class Message { final Map reactions; // userId -> emoji final DateTime? editedAt; final bool isEdited; + final bool isDeleted; Message({ this.id = '', @@ -21,6 +22,7 @@ class Message { this.reactions = const {}, this.editedAt, this.isEdited = false, + this.isDeleted = false, }); factory Message.fromFirestore(DocumentSnapshot doc) { @@ -39,6 +41,7 @@ class Message { reactions: reactionsData?.map((key, value) => MapEntry(key, value.toString())) ?? {}, editedAt: editedAtTimestamp?.toDate(), isEdited: data['isEdited'] ?? false, + isDeleted: data['isDeleted'] ?? false, ); } @@ -52,6 +55,7 @@ class Message { 'reactions': reactions, 'editedAt': editedAt != null ? Timestamp.fromDate(editedAt!) : null, 'isEdited': isEdited, + 'isDeleted': isDeleted, }; } @@ -65,6 +69,7 @@ class Message { Map? reactions, DateTime? editedAt, bool? isEdited, + bool? isDeleted, }) { return Message( id: id ?? this.id, @@ -76,6 +81,7 @@ class Message { reactions: reactions ?? this.reactions, editedAt: editedAt ?? this.editedAt, isEdited: isEdited ?? this.isEdited, + isDeleted: isDeleted ?? this.isDeleted, ); } } \ No newline at end of file diff --git a/lib/repositories/message_repository.dart b/lib/repositories/message_repository.dart index a35dc83..0b96ff9 100644 --- a/lib/repositories/message_repository.dart +++ b/lib/repositories/message_repository.dart @@ -42,7 +42,7 @@ class MessageRepository { }); } - // Supprimer un message + // Supprimer un message (marquer comme supprimé) Future deleteMessage({ required String groupId, required String messageId, @@ -52,7 +52,10 @@ class MessageRepository { .doc(groupId) .collection('messages') .doc(messageId) - .delete(); + .update({ + 'isDeleted': true, + 'text': '', + }); } // Modifier un message