Add new friends system, and sharing legs support
All checks were successful
Release / meta (push) Successful in 9s
Release / linux-build (push) Successful in 6m37s
Release / web-build (push) Successful in 5m29s
Release / android-build (push) Successful in 15m58s
Release / release-master (push) Successful in 20s
Release / release-dev (push) Successful in 26s
All checks were successful
Release / meta (push) Successful in 9s
Release / linux-build (push) Successful in 6m37s
Release / web-build (push) Successful in 5m29s
Release / android-build (push) Successful in 15m58s
Release / release-master (push) Successful in 20s
Release / release-dev (push) Successful in 26s
This commit is contained in:
127
lib/components/widgets/friend_request_notification_card.dart
Normal file
127
lib/components/widgets/friend_request_notification_card.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mileograph_flutter/objects/objects.dart';
|
||||
import 'package:mileograph_flutter/services/data_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FriendRequestNotificationCard extends StatelessWidget {
|
||||
const FriendRequestNotificationCard({super.key, required this.notification});
|
||||
|
||||
final UserNotification notification;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = context.read<DataService>();
|
||||
final friendshipId = notification.body.trim();
|
||||
if (friendshipId.isEmpty) {
|
||||
return const Text('Invalid friend request notification.');
|
||||
}
|
||||
final future = data.fetchFriendshipById(friendshipId);
|
||||
return FutureBuilder<Friendship?>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return const Text('Failed to load request details.');
|
||||
}
|
||||
final friendship = snapshot.data;
|
||||
final requester = friendship?.requester;
|
||||
if (friendship == null || requester == null) {
|
||||
return const Text('Friend request details unavailable.');
|
||||
}
|
||||
final buttonStyle = ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(0, 36),
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.person_add_alt, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
requester.displayName.isNotEmpty
|
||||
? requester.displayName
|
||||
: '@${requester.username}',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
style: buttonStyle,
|
||||
onPressed: () =>
|
||||
_respond(context, friendship.id, accept: true),
|
||||
child: const Text('Accept'),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: buttonStyle,
|
||||
onPressed: () =>
|
||||
_respond(context, friendship.id, accept: false),
|
||||
child: const Text('Reject'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _respond(
|
||||
BuildContext context,
|
||||
String? friendshipId, {
|
||||
required bool accept,
|
||||
}) async {
|
||||
if (friendshipId == null || friendshipId.isEmpty) return;
|
||||
final data = context.read<DataService>();
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
try {
|
||||
if (accept) {
|
||||
await data.acceptFriendship(friendshipId);
|
||||
if (!context.mounted) return;
|
||||
messenger?.showSnackBar(
|
||||
const SnackBar(content: Text('Friend request accepted')),
|
||||
);
|
||||
await _dismissNotification(context, messenger);
|
||||
} else {
|
||||
await data.rejectFriendship(friendshipId);
|
||||
if (!context.mounted) return;
|
||||
messenger?.showSnackBar(
|
||||
const SnackBar(content: Text('Friend request rejected')),
|
||||
);
|
||||
await _dismissNotification(context, messenger);
|
||||
}
|
||||
await data.fetchPendingFriendships();
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
messenger?.showSnackBar(
|
||||
SnackBar(content: Text('Failed to respond: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _dismissNotification(
|
||||
BuildContext context,
|
||||
ScaffoldMessengerState? messenger,
|
||||
) async {
|
||||
try {
|
||||
await context.read<DataService>().dismissNotifications([notification.id]);
|
||||
} catch (e) {
|
||||
messenger?.showSnackBar(
|
||||
SnackBar(content: Text('Failed to dismiss notification: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user