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')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
147
lib/components/widgets/leg_share_notification_card.dart
Normal file
147
lib/components/widgets/leg_share_notification_card.dart
Normal file
@@ -0,0 +1,147 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mileograph_flutter/objects/objects.dart';
|
||||
import 'package:mileograph_flutter/services/data_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class LegShareNotificationCard extends StatelessWidget {
|
||||
const LegShareNotificationCard({super.key, required this.notification});
|
||||
|
||||
final UserNotification notification;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = context.read<DataService>();
|
||||
final legShareId = notification.body.trim();
|
||||
if (legShareId.isEmpty) {
|
||||
return const Text('Invalid leg share notification.');
|
||||
}
|
||||
final future = data.fetchLegShare(legShareId);
|
||||
return FutureBuilder<LegShareData?>(
|
||||
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 shared entry.');
|
||||
}
|
||||
final share = snapshot.data;
|
||||
final entry = share?.entry;
|
||||
if (share == null || entry == null) {
|
||||
return const Text('Shared entry unavailable.');
|
||||
}
|
||||
final begin = entry.beginTime;
|
||||
final beginStr =
|
||||
'${begin.year.toString().padLeft(4, '0')}-${begin.month.toString().padLeft(2, '0')}-${begin.day.toString().padLeft(2, '0')} ${begin.hour.toString().padLeft(2, '0')}:${begin.minute.toString().padLeft(2, '0')}';
|
||||
final start = entry.route.isNotEmpty ? entry.route.first : entry.start;
|
||||
final end = entry.route.isNotEmpty ? entry.route.last : entry.end;
|
||||
final sharedAt = share.sharedAt;
|
||||
final sharedAtStr = sharedAt == null
|
||||
? null
|
||||
: '${sharedAt.year.toString().padLeft(4, '0')}-${sharedAt.month.toString().padLeft(2, '0')}-${sharedAt.day.toString().padLeft(2, '0')} ${sharedAt.hour.toString().padLeft(2, '0')}:${sharedAt.minute.toString().padLeft(2, '0')}';
|
||||
final from = share.sharedFromName;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('$beginStr • $start → $end'),
|
||||
if (from.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
'From $from',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
if (sharedAtStr != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
'Shared at $sharedAtStr',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () => _accept(context, share),
|
||||
child: const Text('Accept'),
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: () => _inspect(context, share),
|
||||
child: const Text('Inspect'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => _reject(context, share),
|
||||
child: const Text('Reject'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _accept(BuildContext context, LegShareData share) async {
|
||||
final data = context.read<DataService>();
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
try {
|
||||
await data.acceptLegShare(share);
|
||||
if (!context.mounted) return;
|
||||
await data.dismissNotifications([notification.id]);
|
||||
// Refresh legs in the background.
|
||||
unawaited(data.refreshLegs());
|
||||
messenger?.showSnackBar(
|
||||
const SnackBar(content: Text('Shared entry added to logbook')),
|
||||
);
|
||||
} catch (e) {
|
||||
messenger?.showSnackBar(
|
||||
SnackBar(content: Text('Failed to add shared entry: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _reject(BuildContext context, LegShareData share) async {
|
||||
final data = context.read<DataService>();
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
try {
|
||||
await data.rejectLegShare(share.id);
|
||||
if (!context.mounted) return;
|
||||
await data.dismissNotifications([notification.id]);
|
||||
messenger?.showSnackBar(
|
||||
const SnackBar(content: Text('Share rejected')),
|
||||
);
|
||||
} catch (e) {
|
||||
messenger?.showSnackBar(
|
||||
SnackBar(content: Text('Failed to reject share: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _inspect(BuildContext context, LegShareData share) async {
|
||||
final router = GoRouter.of(context);
|
||||
// Close notifications panel if open.
|
||||
if (Navigator.canPop(context)) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
final target = share.copyWith(notificationId: notification.id);
|
||||
final ts = DateTime.now().millisecondsSinceEpoch;
|
||||
final path = '/add?share=${Uri.encodeComponent(share.id)}&ts=$ts';
|
||||
router.go(path, extra: target);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user