250 lines
7.5 KiB
Dart
250 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:social_app/core/l10n/l10n.dart';
|
|
|
|
import '../../../../core/theme/design_tokens.dart';
|
|
import '../../../../shared/widgets/app_button.dart';
|
|
import '../../data/inbox_api.dart';
|
|
|
|
class CalendarInviteCard extends StatelessWidget {
|
|
final InboxMessageResponse message;
|
|
final VoidCallback onAccept;
|
|
final VoidCallback onReject;
|
|
|
|
const CalendarInviteCard({
|
|
super.key,
|
|
required this.message,
|
|
required this.onAccept,
|
|
required this.onReject,
|
|
});
|
|
|
|
String? get eventTitle {
|
|
final data = message.content;
|
|
return data?['title'] as String?;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.md,
|
|
vertical: AppSpacing.xs,
|
|
),
|
|
padding: const EdgeInsets.all(AppSpacing.md),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.surface,
|
|
borderRadius: BorderRadius.circular(AppRadius.md),
|
|
border: Border.all(color: colorScheme.outlineVariant),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.primaryContainer,
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
),
|
|
child: Icon(
|
|
Icons.calendar_today,
|
|
color: colorScheme.primary,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Expanded(
|
|
child: Text(
|
|
l10n.messagesCalendarCardInviteTitle,
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: AppSpacing.sm),
|
|
Text(
|
|
eventTitle != null
|
|
? l10n.messagesCalendarCardInviteWithTitle(eventTitle!)
|
|
: l10n.messagesCalendarCardInviteWithoutTitle,
|
|
style: TextStyle(fontSize: 14, color: colorScheme.onSurfaceVariant),
|
|
),
|
|
const SizedBox(height: AppSpacing.md),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: AppButton(
|
|
text: l10n.messagesReject,
|
|
isOutlined: true,
|
|
onPressed: onReject,
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Expanded(
|
|
child: AppButton(
|
|
text: l10n.messagesAccept,
|
|
onPressed: onAccept,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CalendarUpdateCard extends StatelessWidget {
|
|
final InboxMessageResponse message;
|
|
final VoidCallback? onTap;
|
|
|
|
const CalendarUpdateCard({super.key, required this.message, this.onTap});
|
|
|
|
String? get eventTitle {
|
|
final data = message.content;
|
|
return data?['title'] as String?;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.md,
|
|
vertical: AppSpacing.xs,
|
|
),
|
|
padding: const EdgeInsets.all(AppSpacing.md),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.surface,
|
|
borderRadius: BorderRadius.circular(AppRadius.md),
|
|
border: Border.all(color: colorScheme.outlineVariant),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.primaryContainer,
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
),
|
|
child: Icon(
|
|
Icons.calendar_today,
|
|
color: colorScheme.primary,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
eventTitle != null
|
|
? l10n.messagesCalendarCardUpdatedWithTitle(eventTitle!)
|
|
: l10n.messagesCalendarCardUpdatedWithoutTitle,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
_formatTime(context, message.createdAt),
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Icon(Icons.chevron_right, color: colorScheme.outline),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _formatTime(BuildContext context, DateTime time) {
|
|
final l10n = context.l10n;
|
|
final now = DateTime.now();
|
|
final diff = now.difference(time);
|
|
if (diff.inMinutes < 60) {
|
|
return l10n.messagesCalendarCardTimeMinutesAgo(diff.inMinutes);
|
|
} else if (diff.inHours < 24) {
|
|
return l10n.messagesCalendarCardTimeHoursAgo(diff.inHours);
|
|
} else if (diff.inDays < 7) {
|
|
return l10n.messagesCalendarCardTimeDaysAgo(diff.inDays);
|
|
} else {
|
|
return l10n.messagesCalendarCardTimeDate(time.month, time.day);
|
|
}
|
|
}
|
|
}
|
|
|
|
class CalendarDeleteCard extends StatelessWidget {
|
|
final InboxMessageResponse message;
|
|
|
|
const CalendarDeleteCard({super.key, required this.message});
|
|
|
|
String? get eventTitle {
|
|
final data = message.content;
|
|
return data?['title'] as String?;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.md,
|
|
vertical: AppSpacing.xs,
|
|
),
|
|
padding: const EdgeInsets.all(AppSpacing.md),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.surfaceContainerLowest,
|
|
borderRadius: BorderRadius.circular(AppRadius.md),
|
|
border: Border.all(color: colorScheme.outlineVariant),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
),
|
|
child: Icon(
|
|
Icons.calendar_today,
|
|
color: colorScheme.onSurfaceVariant,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Expanded(
|
|
child: Text(
|
|
eventTitle != null
|
|
? l10n.messagesCalendarCardDeletedWithTitle(eventTitle!)
|
|
: l10n.messagesCalendarCardDeletedWithoutTitle,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|